5 Replies
      Latest reply: Aug 22, 2016 5:25 PM by mattn RSS
      mattn Level 1 Level 1 (10 points)

        I don't understand how to write a main.swift file in Swift 3 (current toolchain). We used to write it like this:

         

        UIApplicationMain(
            Process.argc, Process.unsafeArgv, nil, NSStringFromClass(AppDelegate)
        )
        
        

         

        But now that won't compile, because there is a type mismatch between Process.argv, which is typed like this:

         

        UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>
        
        

         

        and the second parameter to UIApplicationMain, which is typed like this:

         

        UnsafeMutablePointer<UnsafeMutablePointer<Int8>>!
        
        

         

        As you can see, they are subtly different. I am able to work around the problem by writing this:

         

        withUnsafeMutablePointer(&Process.unsafeArgv.pointee!) {
            UIApplicationMain(
                Process.argc, $0, nil, NSStringFromClass(AppDelegate)
            )
        }
        
        

         

        But whether that is safe or correct, I have no idea.