NSL*_*Log 21 objective-c ios swift
我正在研究旧项目现在我们正在将所有类转换为swift,如何转换AppDelegate类和该类的集成,我需要更改任何Project设置或main.m.
see*_*eya 48
一个很好的起点是创建一个新的Swift-Project来获取模板AppDelegate,或者只是在你的AppDelegate.swift类中复制以下代码:
@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 throttle down OpenGL ES frame rates. 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:.
}
}
Run Code Online (Sandbox Code Playgroud)
在Swift中main.m,AppDelegate使用@UIApplicationMain注释合并了类和类.因此main.m不再需要.它也不需要更改您的项目设置,因此@UIApplicationMain将为您完成工作.AppDelegate如果您有更多不同的构建目标,请务必设置正确的目标成员资格AppDelegates.
Faw*_*sud 13
1)在Xcode中创建一个新文件(File> New> File ...)并选择一个Cocoa Touch Class.将其命名为AppDelegate,使其成为UIResponder的子类并将语言更改为Swift.
2)用App填充AppDelegate.swift文件
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
return true
}
}
Run Code Online (Sandbox Code Playgroud)
3)删除main.m和main.h文件.
完成!
资料来源:http://www.binpress.com/tutorial/converting-an-objective-c-app-to-swift/118
| 归档时间: |
|
| 查看次数: |
8788 次 |
| 最近记录: |