2017-04-11 16 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