For Swift 3 you can use this code:
let argc = CommandLine.argc
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
which is equivalent of argc
and argv
parameters used in Objective-C main function:
int main(int argc, char *argv[])
For older versions of Swift, you can use Process.argc
and Process.unsafeArgv
or C_ARGC
and C_ARGV
.
You can pass this variables to UIApplicationMain
function in iOS app:
Swift 3:
let argc = CommandLine.argc
let argv = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
UIApplicationMain(argc, argv, nil, NSStringFromClass(AppDelegate.self))
previous Swift versions:
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
or:
UIApplicationMain(C_ARGC, C_ARGC, nil, NSStringFromClass(AppDelegate.self))
Objective-C:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}