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 로드맵 발표
10. 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
20. 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
21. 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
23. 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
24. 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:)
25. 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 }
26. 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
27. 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
29. 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
31. 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
32. 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)
37. 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
38. Swift 3 Foundation
SE-0069: Mutability and Foundation Value
Types
SE-0086: Drop NS Prefix in Swift Foundation
39. 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
40. 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
41. 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
}
}
42. 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