Home > Back-end >  An Xcode warning in swift 5 on UIApplicationMain
An Xcode warning in swift 5 on UIApplicationMain

Time:10-20

In my project there is a main.swift file, with this code in it:

UIApplicationMain(CommandLine.argc,
                  UnsafeMutableRawPointer(CommandLine.unsafeArgv)
                    .bindMemory(
                        to: UnsafeMutablePointer<Int8>.self,
                        capacity: Int(CommandLine.argc)),
                  NSStringFromClass(Application.self),
                  NSStringFromClass(AppDelegate.self)
)

The warning is:

"'UIApplicationMain' is deprecated: Use the overload of UIApplicationMain where the type of the second parameter is UnsafeMutablePointer<UnsafeMutablePointer?>, which is the same as the type of CommandLine.unsafeArgv."

Can anyone elaborate what this warning is saying and give an example of a way to do what it suggests?

Much Appreciated, thanks.

CodePudding user response:

I haven't verified this answer but it's to long for a comment.

which is the same as the type of CommandLine.unsafeArgv."

This seems to imply that you can use CommandLine.unsafeArgv directly. i.e.

UIApplicationMain(CommandLine.argc,
                  CommandLine.unsafeArgv,
                  NSStringFromClass(Application.self),
                  NSStringFromClass(AppDelegate.self)

Even if not, the return type of your bind is UnsafeMutablePointer<UnsafeMutablePointer<Int8>> which is subtly different from what is expected. The generic type for the outer UnsafeMutablePointer is expected to be optional. i.e. UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>

  • Related