Swift 3.0、多くのノイズ、しかし本当に何ですか?





5月上旬、インターネット上で言語開発者は、言語の3.0バージョンのリリースの準備を開始すると発表しました。 リリースによれば、Development 3.0はmasterブランチにあり、5月3日にSwift 2.2.1がリリースされたことを理解できます。 その後、言語の第3バージョンへの変更がそこに注がれ始めました。 5月9日に、同じウィザードの最初の開発者リリースがすでに表示されています。これは、 swift.org / download /#snapshotsからインストーラーを介して最後のxcodeにロールオーバーできます。



今後のリリースに関する一般的な情報



開発者は、Swift 3.0の最初の開発版リリースについて、残念ながら3.0バージョンでABI互換性を実装する時間がないと言いました。 これらすべてが何を意味するのかを理解しましょう。私自身が初めてこれらの3文字を一緒に見ました。



ABIはアプリケーションバイナリインターフェースであり、大まかに言って、異なるバージョンのバイナリ同士の互換性です。API1.0が2.0と互換性がある場合、おなじみのAPI互換性と類推できますが、3.0で行われた変更は最初のバージョンと互換性がないため、APIを使用する場合3.0では、コードを編集する必要があります(ABIの場合、コードを編集せずに、バイナリを再構築します)。



実際、私にとって発見であることが判明したため、SwiftにはABI互換性がありませんでした。 これは、Swift 2.0で構築されたlibが言語の2.2バージョンでは解決されないことを示唆しています。 安定した言語の同僚:







だから、結局のところ、生きている。 しかし、この点に関しては、依存マネージャ(cocoapods、carthage)が常にバイナリではなくプロジェクトソースをプルアップするため、sivivter セーターは幸運でした。したがって、ABIの互換性に問題はありません。 しかし、どうやら今のところ、sfivtに独自のライブラリを書くことを控え、それらをバイナリの形で公開することは価値があります。 はい、彼らはSwift 4.0にのみABIを追加することを約束します。



APIの変更を見てみましょう







didFinishLaunchingメソッドでさえ、警告によって強調表示されます。これは、彼の署名が変更されたためです。



/// swift 3 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]? = [:]) -> Bool {} /// swift 2 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {}
      
      





警告は、将来XcodeでSwift 3.0に移行するために簡単に修正する必要があります。



標準のSwiftライブラリとFoundationの変更点を見てみましょう



ErrorTypeがErrorProtocolに変更されました



 /// swift 3 enum MyError: ErrorProtocol { case Success case Fail(ErrorProtocol) } /// swift 2 enum MyError: ErrorType { case Success case Fail(ErrorType) }
      
      







配列の変更



 /// swift 3 sort() //    sorted() //            /// swift 2 sortInPlace() //    sort() //           
      
      







つまり、 sortメソッドが変更可能になり、 sortInPlaceが削除され、 sortedが追加されました



 /// swift 3 reversed() append(contentsOf: [T]) insert(T, at: Int) joined(separator: String) /// swift 2 reverse() appendContentsOf([T]) insert(T, atIndex: Int) joinWithSeparator(String)
      
      





また、多くのコンストラクタを削除し、他のメソッドの名前を変更しました。



文字列の変更



 /// swift 3 "3.0".components(separatedBy: ".") "3.0".substring(to: 1) "3.0".substring(from: 1) "".data(using: NSUTF8StringEncoding) "2.0".replacingOccurrences(of: "2", with: "3") "".uppercased() "".lowercased() "3.0".contains(".") "3.".appending("0") ("dir1" as NSString).appendingPathComponent("dir2") " 3.0 ".trimmingCharacters(in: .whitespaces()) "".write(toFile: "/..", atomically: true, encoding: NSUTF8StringEncoding) /// swift 2 "3.0".componentsSeparatedByString(".") "3.0".substringToIndex(1) "3.0".substringFromIndex(1) "3.0".dataUsingEncoding(NSUTF8StringEncoding) "2.0".stringByReplacingOccurrencesOfString("2", withString: "3") "".uppercaseString "".lowercaseString "3.0".containsString(".") "3.0".appendContentsOf(".release") ("dir1" as NSString).stringByAppendingPathComponent("dir2") "3.0".stringByTrimmingCharactersInSet(.whitespaceCharacterSet()) "3.0".writeToFile("/..", atomically: true, encoding: NSUTF8StringEncoding)
      
      







enumのケースは恋人のケースになりました



 /// swift 3 UIInterfaceOrientation.portrait Optional.some("") Optional.none /// swift 2 UIInterfaceOrientation.Portrait Optional.Some("") Optional.None
      
      







UIKitの変更



 /// swift 3 let vc = UIViewController() vc.present(some, animated: true, completion: nil) vc.dismiss(animated: true, completion: nil) vc.prepare(for: segue sender: button) UIColor.white() UIColor.blue() let path = UIBezierPath() path.move(to: CGPoint(x: 0, y: 0)) path.addLine(to: CGPoint(x: 100, y: 100)) //   _     +    , -      func tableView(_ tableView: UITableView, numberOfSections section: Int) -> Int { return 0 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell { return UITableViewCell() } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: NSIndexPath) { } /// swift 2 let vc = UIViewController() vc.presentViewController(some, animated: true, completion: nil) vc.dismissViewControllerAnimated(true, completion: nil) vc.prepareForSegue(segue, sender: button) UIColor.whiteColor() UIColor.blueColor() let path = UIBezierPath() path.moveToPoint(CGPoint(x: 0, y: 0)) path.addLineToPoint(CGPoint(x: 100, y: 100)) func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 0 } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { return UITableViewCell() } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { }
      
      







その他の変更



 /// swift 3 NSData(contentsOf: "") UIApplication.shared() NSUserDefaults.standard().set("value", forKey: "key") NSFileManager.default().fileExists(atPath: "/...") NSBundle.main() /// swift 2 NSData(contentsOfURL: "/") UIApplication.sharedApplication() NSUserDefaults.standardUserDefaults().setObject("value", forKey: "key") NSFileManager.defaultManager().fileExistsAtPath("/") NSBundle.mainBundle()
      
      







これは、一般的な標準ライブラリだけでなく、API全体が破損した、高速化の実行方法です。 しかし、私は認めなければなりません、読みやすさは本当に良くなりました。 リリースSwift 3.0は秋に予定されています。 ABI互換性は4.0で予定されています。 WWDC 2016では、Swiftの新しい機能は期待できません。



疑問が生じるので、なぜ新しいプロジェクトを選択するのですか? 私はSwiftに投票します。オプションの形式の非常に厳密な入力とループとクロージャー/ラムダの構文のために、開発がはるかに速くて安全です。 一般的に:







便利なリンク:



https://swift.org/blog/

https://www.hackingwithswift.com/swift3

https://github.com/apple/swift-evolution

http://www.bensnider.com/abi-compatibility-whoopdty-do-what-does-it-all-mean.html



更新する



Swiftの開発者がAPI全体をシャベルで作り、言語の最初の日から意図したとおりにしたことを追加する価値があります。Objective-Cとの互換性のサポートだけで、元のAPIデザインが壊れました。 Swiftは、FreeBSD、Raspberry Pi、Android、Windowsなどの多くのプラットフォームで動作する予定です。 どうやら、バージョン3.0で、より迅速なスタイルを提供するためにAPIを完全に再設計することにしました。



All Articles