2015年12月17日木曜日

レガシーな Objective-C プロジェクトを Swift なプロジェクトに変換する

Objective-C


iOS 7 (Xcode 5) 

Swift

IOS_DEPLOYMENT_TARGET8.0 (7.x)



iOSSwift

IOS_DEPLOYMENT_TARGET8.0IOS_DEPLOYMENT_TARGET8.0dynamic frameworkclang module使Objective-CSwift

1: Objective-CSwift

SwiftXcode

clang moduledyld使
CLANG_ENABLE_MODULES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

Swift
SWIFT_OBJC_BRIDGING_HEADER = "myapp/myapp-Bridging-Header.h";

Release
SWIFT_OPTIMIZATION_LEVEL = "-Onone";

使Objective-C

2: Swift

Swiftmain.mCmain


AppDelegate.swift

Objective-CAppDelegateswiftAppDelegate@UIApplicationMain

main.m

: http://stackoverflow.com/questions/31309249/how-to-convert-objective-c-appdelegate-to-swift

Swift

Swift

AppDelegate.swiftSwiftAppDelegateSwift


UIWindowAppDelegate

UIApplicationmain.m

Swift

UIApplicationInfo.plistNSPrincipalClass: http://stackoverflow.com/questions/31642956/how-to-detect-all-touches-in-swift-2

UIWindowMain.storyboard使UIWindowawakeFromNib
@UIApplicationMain
class MyAppDelegate: NSObject, UIResponder, UIApplicationDelegate {
  var window: UIWindow?
  override func awakeFromNib() {
    super.awakeFromNib()
    guard let defaultWindow = self.window else {
      fatalError("Something is wrong")
    }
    let window = MySuperDuperWindow()
    window.rootViewController = defaultWindow.rootViewController
    self.window = window
  }
}