2017-04-11 4 views
0

私はappをobjective-cとswift(元はobjective-c)に混ぜています.2人のアプリケーションデリゲートを持つ方法を理解する必要がありますもう一方は目的のために - c)。私はいくつかの研究をしましたが、何も見つかりませんでした。助けてください!2人のアプリケーションデリゲート、swiftとobjective-c

EDIT:だから

、私は正常に切り替え、今は私の代理人に、私はこのコードを持っている:

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

できません。アプリは1つのデリゲートしか持つことができず、スウィフトまたは目的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

あなたは両方を持つことはできません...もしあなたがこの1つを使用したいのであれば、他のものを削除する必要があります。 –

+0

私はそれをしましたが、今は非常に多くのエラーが発生しています。 – user7847400

関連する問題