2017-04-11 45 views
0

所以,我有一個混合了objective-c和swift的應用程序(最初是objective-c)我需要弄清楚如何擁有2個應用程序代表(一個用於swift,另一個用於objective-c)。我做了一些研究,但什麼都沒發現。請幫忙!2應用程序代表,swift和objective-c

編輯:

所以,我成功地切換,但現在在我的委託,我有這樣的代碼:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    let splitViewController = window!.rootViewController as! UISplitViewController 
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController 
    navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem 
    splitViewController.delegate = self 
    return true 
} 

但是,splitViewController不是第一個VC,所以我會怎樣去修復它? (我不太清楚)

+2

你不能。應用程序只能有一個代表,如果要在Swift或Objective C中執行,則必須選擇它。 –

+0

如果我在快速執行該代碼,是否會混淆其他代碼?我該如何去做這件事 – user7847400

回答

0

你只需要一個代表,在Swift中執行。如果您創建一個新的應用程序的Xcode會使用一些默認代碼,這爲8.3.1如下:

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
     // Override point for customization after application launch. 
     return true 
    } 

    func applicationWillResignActive(_ application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(_ application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(_ application: UIApplication) { 
     // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(_ application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(_ application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 

要回答的註釋:它不會弄亂你的代碼。如果需要,刪除以前的Objective C委託。

+0

因此,刪除舊的應用程序委託,並把一個新的? – user7847400

+0

你不能同時擁有兩個...所以如果你想使用這個,你必須刪除其他 –

+0

我已經這樣做了,但現在我得到了這麼多的錯誤。 – user7847400

相關問題