Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Letswift Swift 3.0

8,691 views

Published on

SE를 통해 본 스위프트 3.0의 변화

Published in: Software
  • Dating for everyone is here: ♥♥♥ http://bit.ly/2Qu6Caa ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❶❶❶ http://bit.ly/2Qu6Caa ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Letswift Swift 3.0

  1. 1. letswift(16) 스위프트 3.0 Swift는 어디로 가는가 OSXDEV.org박세현
  2. 2. Agenda Swift 역사 Swift 3.0 훑어보기 Swift Evolution & 구현
  3. 3. Swift History 2010년 7월 Swift 개발 시작 2014년 6월 2일 WWDC 앱 Swift로 작성된 공개 앱. 2014년 9월 9일 Swift 1.0 마일스톤 2014년 10월 22일 Swift 1.1 2015년 4월 8일 Swift 1.2 2015년 WWDC Swift 2.0 발표 2015년 12월 3일 Swift 오픈소스 발표, 3.0 로드맵 발표
  4. 4. Swift 1.2 성능향상 if-let 개선(바인딩) as 키워드로 업캐스팅/다운캐스팅 Set 추가 Objective-C 옵셔널 수식어 추가
  5. 5. Swift 2.0 에러처리 throw, do try catch guard let ­ else 프로토콜 익스텐션 Objective-C 제네릭
  6. 6. Swift 3.0 예상 발표일: 2016 말 Swift 언어와 개발 경험 강화 Swift 3.0과 이후 버전의 소스 호환성 http://bekher.net/2015/06/the-next-step-for-swift/
  7. 7. Swift 3.0 Focus API 디자인 가이드라인 임포트한 Obj-C API에 네이밍 가이드라인 자동 적용 핵심 API에 네이밍 가이드라인 도입 임포트한 Obj-C API의 Swift화 언어의 집중 및 정교화 툴 품질 향상
  8. 8. API Design Guideline 기본 원칙 사용 시점의 명확성 짧은 것보다 명확한 것이 더 중요 모든 선언마다 주석으로 문서화
  9. 9. Swift Evolution Language Evolution Process Socialize ➔ Proposal(PR) ➔ Review ➔ Decision Swift Evolution Process https://swift.org/community/#mailing-lists https://lists.swift.org/mailman/listinfo/swift-evolution https://github.com/apple/swift- evolution#implemented-proposals-for-swift-3
  10. 10. Swift Evolution: Example SE-0031: Adjusting inout Declarations for Type Decoration 메일링 리스트 논의 PR SE 수락
  11. 11. SE-0031 Adjusting 'inout' Declarations for Type Decoration Swift 2 Swift 3 (x: inout T) -> U // => (inout T) -> U func foo(inOut x: T) // foo(inOut:), type (T) -> Void func foo(inout x: T) // foo(_:), type (inout T) -> Void
  12. 12. letswift(16) Core Language
  13. 13. Swift 3 Removals SE-0002: Removing currying func declaration syntax SE-0003: Removing var from Function Parameters SE-0004: Remove the ++ and -- operators SE-0007: Remove C-style for-loops with conditions and incrementers SE-0029: Remove implicit tuple splat behavior from function applications SE-0053: Remove explicit use of let from Function Parameters
  14. 14. SE-0003: Removing var from Function Parameters func foo(i: Int) { i += 1 // illegal } func foo(var i: Int) { i += 1 // OK, but the caller cannot observe this mutation. } func doSomethingWithVar(var i: Int) { i = 2 // This will NOT have an effect on the caller's Int that was passed, but it can be modified locally } func doSomethingWithInout(inout i: Int) { i = 2 // This will have an effect on the caller's Int that was passed. } var x = 1 print(x) // 1 doSomethingWithVar(x) print(x) // 1 doSomethingWithInout(&x) print(x) // 2
  15. 15. SE-0003: 기존 코드 func foo(i: Int) { var i = i }
  16. 16. Swift 3 Functions SE-0042: Flattening the function type of unapplied method references SE-0046: Establish consistent label behavior across all parameters including first labels SE-0047: Defaulting non-Void functions so they warn on unused results SE-0066: Standardize function type argument syntax to require parentheses SE-0110: Distinguish between single-tuple and multiple-argument function types SE-0111: Remove type system significance of function argument labels
  17. 17. SE-0046 Establish consistent label behavior across all parameters including first labels Swift 2 Swift 3 func foo(a: T, b: U, c: V) foo(_:b:c:) func foo(a: T, b: U, c: V) foo(a:b:c:) func foo(_: T, b: U, c: V) foo(_:b:c:)
  18. 18. SE-0110 Distinguish between single-tuple and multiple- argument function types Swift 2 Swift 3 let fn1 : (Int, Int) -> Void = { x in // The type of x is the tuple (Int, Int). // ... } let fn2 : (Int, Int) -> Void = { x, y in // The type of x is Int, the type of y is Int. // ... } let a : ((Int, Int, Int)) -> Int = { x in return x.0 + x.1 + x.2 }
  19. 19. Swift 3 Optional SE-0008: Add a Lazy flatMap for Sequences of Optionals SE-0054: Abolish ImplicitlyUnwrappedOptional type SE-0055: Make unsafe pointer nullability explicit using Optional
  20. 20. Swift 3 Debugging & Testing SE-0019: Swift Testing SE-0028: Modernizing Swift's Debugging Identifiers (__FILE__, etc) SE-0034: Disambiguating Line Control Statements from Debugging Identifiers SE-0039: Modernizing Playground Literals
  21. 21. Modernizing Swift's Debugging Identifiers Swift offers built-in __FILE__, __LINE__, __COLUMN__, __FUNCTION__, and __DSO_HANDLE__ identifiers __FILE__ ➔ #file __LINE__ ➔ #line __COLUMN__ ➔ #column __FUNCTION__ ➔ #function (Added during review) __DSO_HANDLE__ ➔ #dsohandle SE-0028
  22. 22. Swift 3 Swift Library SE-0016: Adding initializers to Int and UInt to convert from UnsafePointer and UnsafeMutablePointer SE-0032: Add first(where:) method to SequenceType SE-0052: Change IteratorType post-nil guarantee SE-0065: A New Model For Collections and Indices SE-0094: Add sequence(first:next:) and sequence(state:next:) to the stdlib
  23. 23. letswift(16) API & Foundation
  24. 24. Swift 3 API Design Guidelines Swift API Design Guidelines SE-0005: Better Translation of Objective-C APIs Into Swift SE-0006: Apply API Guidelines to the Standard Library SE-0023: API Design Guidelines SE-0059: Update API Naming Guidelines and Rewrite Set APIs Accordingly
  25. 25. SE-0005 Better Translation of Objective-C APIs Into Swift Objective-C API Swifty version let content = listItemView.text.stringByTrimmingCharactersInSet( NSCharacterSet.whitespaceAndNewlineCharacterSet()) let content = listItemView.text.trimming(.whitespaceAndNewlines)
  26. 26. SE-0005 UIBezierPath in Swift 2 class UIBezierPath : NSObject, NSCopying, NSCoding { convenience init(ovalInRect: CGRect) func moveToPoint(_: CGPoint) func addLineToPoint(_: CGPoint) func addCurveToPoint(_: CGPoint, controlPoint1: CGPoint, controlPoint2: CGPoint) func addQuadCurveToPoint(_: CGPoint, controlPoint: CGPoint) func appendPath(_: UIBezierPath) func bezierPathByReversingPath() -> UIBezierPath func applyTransform(_: CGAffineTransform) var empty: Bool { get } func containsPoint(_: CGPoint) -> Bool func fillWithBlendMode(_: CGBlendMode, alpha: CGFloat) func strokeWithBlendMode(_: CGBlendMode, alpha: CGFloat) func copyWithZone(_: NSZone) -> AnyObject func encodeWithCoder(_: NSCoder) }
  27. 27. SE-0005 UIBezierPath in Swift 3 class UIBezierPath : NSObject, NSCopying, NSCoding { convenience init(ovalIn rect: CGRect) func move(to point: CGPoint) func addLine(to point: CGPoint) func addCurve(to endPoint: CGPoint, controlPoint1 controlPoint1: CGPoint, controlPoint2 controlPoint2: CGPoint) func addQuadCurve(to endPoint: CGPoint, controlPoint controlPoint: CGPoint) func append(_ bezierPath: UIBezierPath) func reversing() -> UIBezierPath func apply(_ transform: CGAffineTransform) var isEmpty: Bool { get } func contains(_ point: CGPoint) -> Bool func fill(_ blendMode: CGBlendMode, alpha alpha: CGFloat) func stroke(_ blendMode: CGBlendMode, alpha alpha: CGFloat) func copy(with zone: NSZone = nil) -> AnyObject func encode(with aCoder: NSCoder) }
  28. 28. SE-0006 Strip Type Suffix from protocol names -public protocol BooleanType { ... } +public protocol Boolean { ... } -public protocol SequenceType { ... } +public protocol Sequence { ... } -public protocol CollectionType : ... { ... } +public protocol Collection : ... { ... } -public protocol MutableCollectionType : ... { ... } +public protocol MutableCollection : ... { ... } -public protocol RangeReplaceableCollectionType : ... { ... } +public protocol RangeReplaceableCollection : ... { ... } -public protocol AnyCollectionType : ... { ... } +public protocol AnyCollectionProtocol : ... { ... } -public protocol IntegerType : ... { ... } +public protocol Integer : ... { ... }
  29. 29. SE-0006 renamed functions sort() ➔ sorted() sortInPlace() ➔ sort() reverse() ➔ reversed() enumerate() ➔ enumerated()
  30. 30. SE-0006 New importing rules extension String { - public static func localizedNameOfStringEncoding( - encoding: NSStringEncoding - ) -> String + public static func localizedName( + ofStringEncoding encoding: NSStringEncoding + ) -> String - public static func pathWithComponents(components: [String]) -> String + public static func path(withComponents components: [String]) -> String - public init?(UTF8String bytes: UnsafePointer<CChar>) + public init?(utf8String bytes: UnsafePointer<CChar>) - public func canBeConvertedToEncoding(encoding: NSStringEncoding) -> Bool + public func canBeConverted(toEncoding encoding: NSStringEncoding) -> Bool - public var capitalizedString: String + public var capitalized: String - public var localizedCapitalizedString: String + public var localizedCapitalized: String
  31. 31. Swift 3 Foundation SE-0069: Mutability and Foundation Value Types SE-0086: Drop NS Prefix in Swift Foundation
  32. 32. SE-0069 Mutability and Foundation Value Types Objective-C API let myDate = Date() let myLaterDate = myDate.dateByAddingTimeInterval(60) var myDate = Date() myDate.addTimeInterval(60) // OK let myOtherDate = Date() myOtherDate.addTimeInterval(60) // Error, as expected
  33. 33. SE-0086 Drop NS Prefix in Swift Foundation Objective-C Name Swift Name NSAttributedString AttributedString NSBlockOperation BlockOperation NSBundle Bundle NSByteCountFormatter ByteCountFormatter NSCache Cache NSCacheDelegate CacheDelegate NSCachedURLResponse CachedURLResponse NSCalendar Calendar NSComparisonPredicate ComparisonPredicate NSComparisonResult ComparisonResult NSCompoundPredicate CompoundPredicate
  34. 34. SE-0086 Enumerations extension DateIntervalFormatter { @available(OSX 10.10, iOS 8.0, *) public enum Style : UInt { case none case short case medium case long case full } } extension NumberFormatter { public enum Style : UInt { case none case decimal case currency case percent case scientific case spellOut @available(OSX 10.11, iOS 9.0, *) case ordinal @available(OSX 10.11, iOS 9.0, *) case currencyISOCode @available(OSX 10.11, iOS 9.0, *) case currencyPlural @available(OSX 10.11, iOS 9.0, *) case currencyAccounting } }
  35. 35. Swift 3 Objective-C SE-0062: Referencing Objective-C key-paths SE-0064: Referencing the Objective-C selector of property getters and setters SE-0070: Make Optional Requirements Objective-C- only SE-0033: Import Objective-C Constants as Swift Types SE-0057: Importing Objective-C Lightweight Generics
  36. 36. References https://en.wikipedia.org/wiki/ Swift_(programming_language) https://swift.org/documentation/api-design-guidelines/ https://developer.apple.com/videos/play/wwdc2016/402/ https://developer.apple.com/videos/play/wwdc2016/207/ https://github.com/apple/swift-evolution#implemented- proposals-for-swift-3 https://www.raywenderlich.com/135655/whats-new-swift-3
  37. 37. –Johnny Appleseed “Swift 3 is awesome.”
  38. 38. letswift(16)

×