0
# iOS Platform Types
1
2
Complete iOS platform configuration types with CocoaPods integration, Xcode project handling, and script phase management for React Native development.
3
4
## Capabilities
5
6
### iOS Project Configuration
7
8
Complete iOS project configuration defining Xcode project structure, CocoaPods settings, and development workflow parameters.
9
10
```typescript { .api }
11
/**
12
* Complete iOS project configuration
13
*/
14
interface IOSProjectConfig {
15
/** Source directory containing iOS code (e.g., "ios") */
16
sourceDir: string;
17
/** Xcode project information (null if no Xcode project found) */
18
xcodeProject: IOSProjectInfo | null;
19
/** Additional command parameters for watch mode */
20
watchModeCommandParams?: string[];
21
/** Whether to automatically run 'pod install' */
22
automaticPodsInstallation?: boolean;
23
/** Asset directories for this platform */
24
assets: string[];
25
}
26
27
/**
28
* Xcode project information
29
*/
30
type IOSProjectInfo = {
31
/** Project or workspace name */
32
name: string;
33
/** Path to .xcodeproj or .xcworkspace file */
34
path: string;
35
/** Whether this is a workspace (.xcworkspace) or project (.xcodeproj) */
36
isWorkspace: boolean;
37
};
38
```
39
40
**Usage Examples:**
41
42
```typescript
43
import { IOSProjectConfig, IOSProjectInfo } from "@react-native-community/cli-types";
44
45
// Standard iOS project configuration
46
const iosConfig: IOSProjectConfig = {
47
sourceDir: "ios",
48
xcodeProject: {
49
name: "MyReactNativeApp",
50
path: "ios/MyReactNativeApp.xcodeproj",
51
isWorkspace: false
52
},
53
watchModeCommandParams: ["--verbose"],
54
automaticPodsInstallation: true,
55
assets: ["./ios/MyReactNativeApp/Images.xcassets"]
56
};
57
58
// Configuration with workspace
59
const workspaceConfig: IOSProjectConfig = {
60
sourceDir: "ios",
61
xcodeProject: {
62
name: "MyReactNativeApp",
63
path: "ios/MyReactNativeApp.xcworkspace",
64
isWorkspace: true
65
},
66
automaticPodsInstallation: true,
67
assets: []
68
};
69
70
// Configuration without Xcode project
71
const noXcodeConfig: IOSProjectConfig = {
72
sourceDir: "ios",
73
xcodeProject: null,
74
automaticPodsInstallation: false,
75
assets: []
76
};
77
78
// Validate iOS configuration
79
function validateIOSConfig(config: IOSProjectConfig): boolean {
80
if (!config.sourceDir) return false;
81
82
if (config.xcodeProject) {
83
return !!(config.xcodeProject.name && config.xcodeProject.path);
84
}
85
86
return true;
87
}
88
89
// Get build command based on project type
90
function getBuildCommand(config: IOSProjectConfig): string {
91
if (!config.xcodeProject) return "";
92
93
const buildTarget = config.xcodeProject.isWorkspace ?
94
`-workspace "${config.xcodeProject.path}"` :
95
`-project "${config.xcodeProject.path}"`;
96
97
return `xcodebuild ${buildTarget} -scheme ${config.xcodeProject.name}`;
98
}
99
```
100
101
### iOS Project Parameters
102
103
Input parameters for configuring iOS projects with optional fields for auto-detection.
104
105
```typescript { .api }
106
/**
107
* Parameters for iOS project configuration with optional auto-detection fields
108
*/
109
interface IOSProjectParams {
110
/** Source directory (optional, will be detected if not provided) */
111
sourceDir?: string;
112
/** Additional command parameters for watch mode */
113
watchModeCommandParams?: string[];
114
/** Whether to automatically run 'pod install' */
115
automaticPodsInstallation?: boolean;
116
/** Asset directories */
117
assets?: string[];
118
}
119
```
120
121
**Usage Examples:**
122
123
```typescript
124
import { IOSProjectParams } from "@react-native-community/cli-types";
125
126
// Minimal iOS parameters (auto-detection)
127
const minimalParams: IOSProjectParams = {
128
automaticPodsInstallation: true
129
};
130
131
// Full iOS parameters
132
const fullParams: IOSProjectParams = {
133
sourceDir: "ios",
134
watchModeCommandParams: ["--verbose", "--simulator", "iPhone 14"],
135
automaticPodsInstallation: true,
136
assets: ["./assets", "./ios/MyApp/Images.xcassets"]
137
};
138
139
// Parameters for manual CocoaPods management
140
const manualPodsParams: IOSProjectParams = {
141
sourceDir: "ios",
142
automaticPodsInstallation: false,
143
assets: []
144
};
145
146
// Create parameters from existing config
147
function paramsFromConfig(config: IOSProjectConfig): IOSProjectParams {
148
return {
149
sourceDir: config.sourceDir,
150
watchModeCommandParams: config.watchModeCommandParams,
151
automaticPodsInstallation: config.automaticPodsInstallation,
152
assets: config.assets
153
};
154
}
155
```
156
157
### iOS Dependency Configuration
158
159
CocoaPods-based dependency configuration with script phases and build configuration support.
160
161
```typescript { .api }
162
/**
163
* iOS dependency configuration using CocoaPods
164
*/
165
interface IOSDependencyConfig {
166
/** Path to the podspec file */
167
podspecPath: string;
168
/** Version of the dependency */
169
version: string;
170
/** CocoaPods script phases for this dependency */
171
scriptPhases: Array<IOSScriptPhase>;
172
/** Xcode configurations this dependency supports (e.g., ["Debug", "Release"]) */
173
configurations: string[];
174
}
175
176
/**
177
* CocoaPods script phase configuration
178
* Based on CocoaPods script_phase DSL: https://www.rubydoc.info/gems/cocoapods-core/Pod/Podfile/DSL#script_phase-instance_method
179
*/
180
type IOSScriptPhase = ({script: string} | {path: string}) & {
181
/** Name of the script phase */
182
name: string;
183
/** Shell path for script execution (optional, defaults to /bin/sh) */
184
shell_path?: string;
185
/** Input files for the script phase */
186
input_files?: string[];
187
/** Output files for the script phase */
188
output_files?: string[];
189
/** Input file lists for the script phase */
190
input_file_lists?: string[];
191
/** Output file lists for the script phase */
192
output_file_lists?: string[];
193
/** Whether to show environment variables in build log */
194
show_env_vars_in_log?: boolean;
195
/** When to execute the script phase */
196
execution_position?: 'before_compile' | 'after_compile' | 'any';
197
/** Dependency file for incremental builds */
198
dependency_file?: string;
199
/** Whether script is always out of date (always runs) */
200
always_out_of_date?: string;
201
};
202
```
203
204
**Usage Examples:**
205
206
```typescript
207
import { IOSDependencyConfig, IOSScriptPhase } from "@react-native-community/cli-types";
208
209
// Simple iOS library dependency
210
const simpleDependency: IOSDependencyConfig = {
211
podspecPath: "./ios/MyLibrary.podspec",
212
version: "1.0.0",
213
scriptPhases: [],
214
configurations: ["Debug", "Release"]
215
};
216
217
// Script phase with inline script
218
const inlineScriptPhase: IOSScriptPhase = {
219
name: "Generate Assets",
220
script: "echo 'Generating assets...' && node scripts/generate-assets.js",
221
shell_path: "/bin/bash",
222
execution_position: "before_compile",
223
show_env_vars_in_log: true,
224
input_files: ["scripts/generate-assets.js"],
225
output_files: ["${BUILT_PRODUCTS_DIR}/generated-assets.json"]
226
};
227
228
// Script phase with external file
229
const fileScriptPhase: IOSScriptPhase = {
230
name: "Build Native Module",
231
path: "./scripts/build-native.sh",
232
execution_position: "after_compile",
233
input_file_lists: ["${SRCROOT}/native-sources.xcfilelist"],
234
output_file_lists: ["${BUILT_PRODUCTS_DIR}/native-outputs.xcfilelist"],
235
dependency_file: "${TEMP_DIR}/native-deps.d"
236
};
237
238
// Complex dependency with script phases
239
const complexDependency: IOSDependencyConfig = {
240
podspecPath: "./react-native-my-native-module.podspec",
241
version: "2.1.0",
242
scriptPhases: [
243
{
244
name: "Prepare Build Environment",
245
script: "mkdir -p ${BUILT_PRODUCTS_DIR}/native-temp",
246
execution_position: "before_compile"
247
},
248
{
249
name: "Post-build Cleanup",
250
path: "./scripts/ios-cleanup.sh",
251
shell_path: "/bin/bash",
252
execution_position: "after_compile",
253
show_env_vars_in_log: false
254
}
255
],
256
configurations: ["Debug", "Release", "Staging"]
257
};
258
259
// Validate script phase
260
function validateScriptPhase(phase: IOSScriptPhase): boolean {
261
const hasScript = 'script' in phase && !!phase.script;
262
const hasPath = 'path' in phase && !!phase.path;
263
264
return (hasScript || hasPath) && !!phase.name;
265
}
266
267
// Get script content for phase
268
function getScriptContent(phase: IOSScriptPhase): string {
269
if ('script' in phase) return phase.script;
270
if ('path' in phase) return `source "${phase.path}"`;
271
return "";
272
}
273
```
274
275
### iOS Dependency Parameters
276
277
Input parameters for configuring iOS dependencies with optional fields for auto-detection.
278
279
```typescript { .api }
280
/**
281
* Parameters for iOS dependency configuration (excludes podspecPath and version which are auto-detected)
282
*/
283
type IOSDependencyParams = Omit<
284
Partial<IOSDependencyConfig>,
285
'podspecPath' | 'version'
286
>;
287
```
288
289
**Usage Examples:**
290
291
```typescript
292
import { IOSDependencyParams, IOSScriptPhase } from "@react-native-community/cli-types";
293
294
// Minimal dependency parameters (auto-detection)
295
const minimalDependencyParams: IOSDependencyParams = {};
296
297
// Parameters with custom configurations
298
const customConfigParams: IOSDependencyParams = {
299
configurations: ["Debug", "Release", "Staging"],
300
scriptPhases: []
301
};
302
303
// Parameters with script phases
304
const scriptPhasesParams: IOSDependencyParams = {
305
scriptPhases: [
306
{
307
name: "Bundle React Native Code",
308
script: "npx react-native bundle --platform ios --dev false",
309
execution_position: "before_compile",
310
output_files: ["${BUILT_PRODUCTS_DIR}/main.jsbundle"]
311
}
312
],
313
configurations: ["Debug", "Release"]
314
};
315
316
// Convert to full config (simulated auto-detection)
317
function simulateIOSConfigGeneration(
318
params: IOSDependencyParams,
319
detectedPodspecPath: string,
320
detectedVersion: string
321
): IOSDependencyConfig {
322
return {
323
podspecPath: detectedPodspecPath,
324
version: detectedVersion,
325
scriptPhases: params.scriptPhases || [],
326
configurations: params.configurations || ["Debug", "Release"]
327
};
328
}
329
```
330
331
### Platform Integration
332
333
How iOS types integrate with the broader platform configuration system.
334
335
**Usage Examples:**
336
337
```typescript
338
import { Config, IOSProjectParams, IOSDependencyParams } from "@react-native-community/cli-types";
339
340
// The iOS platform configuration is accessed through Config.platforms.ios
341
// Note: IOSPlatformConfig type is not exported, but the platform is accessible
342
343
// Generate iOS project config from parameters
344
function generateIOSProjectConfig(
345
config: Config,
346
projectRoot: string,
347
params?: IOSProjectParams
348
): IOSProjectConfig | void {
349
return config.platforms.ios.projectConfig(projectRoot, params);
350
}
351
352
// Generate iOS dependency config
353
function generateIOSDependencyConfig(
354
config: Config,
355
dependency: string,
356
params: IOSDependencyParams
357
): IOSDependencyConfig | void {
358
return config.platforms.ios.dependencyConfig(dependency, params);
359
}
360
361
// Check if project has iOS support
362
function hasIOSSupport(config: Config): boolean {
363
return !!config.project.ios;
364
}
365
366
// Get iOS build settings
367
function getIOSBuildSettings(config: Config) {
368
const iosProject = config.project.ios;
369
if (!iosProject) return null;
370
371
return {
372
sourceDir: iosProject.sourceDir,
373
projectName: iosProject.xcodeProject?.name,
374
projectPath: iosProject.xcodeProject?.path,
375
isWorkspace: iosProject.xcodeProject?.isWorkspace || false,
376
automaticPods: iosProject.automaticPodsInstallation || false
377
};
378
}
379
380
// Count script phases across all iOS dependencies
381
function countIOSScriptPhases(config: Config): number {
382
return Object.values(config.dependencies)
383
.map(dep => dep.platforms.ios?.scriptPhases?.length || 0)
384
.reduce((total, count) => total + count, 0);
385
}
386
387
// Access iOS platform through config
388
function getIOSSettings(config: Config) {
389
const iosPlatform = config.platforms.ios;
390
return {
391
npmPackageName: iosPlatform.npmPackageName,
392
hasProjectConfig: typeof iosPlatform.projectConfig === 'function',
393
hasDependencyConfig: typeof iosPlatform.dependencyConfig === 'function'
394
};
395
}
396
```