如何将AppDelegate从Swift转换回Objective C?

时间:2014-12-29 10:49:28

标签: ios objective-c swift xcode6 appdelegate

我有一个我创建的项目作为新的Swift项目,我需要将它的AppDelegate转换回Objective C后我已经做了很多改变,所以它不像创建新项目那么容易

注意:我们需要这个,因为我们有一个项目需要快速完成,没有时间去探索swift。

1 个答案:

答案 0 :(得分:6)

删除AppDelegate.swift并添加以下文件:

AppDelegate.h

//
//  AppDelegate.h
//  Shereef
//
//  Created by Shereef Marzouk on 12/29/14.
//  Copyright (c) 2014 X Digital Group. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

AppDelegate.m

//
//  AppDelegate.m
//  Shereef
//
//  Created by Shereef Marzouk on 12/29/14.
//  Copyright (c) 2014 X Digital Group. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // 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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // 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.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // 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.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // 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.
}

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

@end

的main.m

//
//  main.m
//  Shereef
//
//  Created by Shereef Marzouk on 12/29/14.
//  Copyright (c) 2014 X Digital Group. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}