Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swift Weekly 7/26

Swift Weekly 7/26

Johnlin

July 26, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Swift 3.0 ࠷৽࣌ఔ • 7/27 ੋ઀ड breaking change త࠷ޙҰఱ •

    7/27 ။౼࿦ཁዎኄ႔ཧೝՄୠؐᔒመ࡞తमվ • 8/1 ։࢝౼࿦ Swift 4 • Swift 3 త ᚙߦ೔ؐᔒ֬ఆɼୠҰఆࡏ 7/27 ೭ޙ
  2. Evolution • SE-0077 վਐӡࢉࢠએࠂ • SE-0110 ე෼ᄸҰTuple ᢛ ଟჩᏐവᏐ •

    SE-0111 വᏐతჩᏐඪតෆ࠶ੋܕผతҰ෦㟨 • SE-0113 ුᴍᏐ৽⃧ਐҐ/ࣺڈവᏐ
  3. SE-0077 վਐӡࢉࢠએࠂ // Before infix operator <> { precedence 100

    associativity left } // After precedencegroup ComparationPrecedence { associativity: left higherThan: LogicalAndPrecedence } infix operator <> : ComparationPrecedence
  4. SE-0110 ე෼ᄸҰTuple ᢛ ଟჩ ᏐവᏐ 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. } // Future let fn1 : ((Int, Int)) -> Void = { x in // The type of x is the tuple (Int, Int). }
  5. SE-0111 വᏐతჩᏐඪតෆ࠶ੋ ܕผతҰ෦㟨 func viewExistAt(x:Int, y:Int) -> Bool { return

    false } func deleteViewAt(dangerX:Int, dangerY:Int) -> Bool { print("") return true } var f :(x: Int, y: Int) -> Bool = viewExistAt f(x: 1,y: 2) f = deleteViewAt f(x: 1,y: 2) //
  6. SE-0111 വᏐతჩᏐඪតෆ࠶ੋ ܕผతҰ෦㟨 // ະိ let f : (x: Int,

    y: Int) -> Bool //။㗞ੜࡨޡ // ୞ೳ༻ let f : (Int, Int) -> Bool // ݺڣ࣌ෆೳትlabel f(1,2)
  7. SE-0113 ුᴍᏐ৽⃧ਐҐ/ࣺڈവ Ꮠ • FloatingPoint ৽⃧ round , rounded വᏐ

    • แؚ֤छਐҐ/ࣺڈํ๏ɼ toNearestOrAwayFromZero(࢛ࣺޒೖɼ༬ઃᆴ),up(ແ ᑍ݅ਐҐ),down(ແᑍࣺ݅ڈ), towardZero, awayFromZero, toNearestOrEven(IEEE 754 default) • (4.5).rounded() == 5.0 • (4.1).rounded(.up) == 5.0
  8. Evolution • SE-0086 ҠআFoundation త NS લஔࢺ • SE-0091 վਐ

    Protocol தత operator એࠂํࣜ • SE-0107 UnsafeRawPointer API • SE-0109 Ҡআ Boolean protocol
  9. SE-0086 ҠআFoundation త NS લஔࢺ • جຊ্શ౎။ҠআNS ։಄ɼআྃҎԼزݸྫ֎ • Obj-c

    ಛ༗త: NSObject, NSAutoreleasePool … • ࿨ฏ୆༗᮫త: NSUserNotification, NSBackgroundActivity … • ༗value ൛త: NSArray, NSString…
  10. SE-0086 ҠআFoundation త NS લஔࢺ • ᄸ७ҠআNS ։಄త༗ 86 ݸ

    Classɻ แؚ: NSBundle, NSTimeInterval, NSURLRequest… • ။վ໊త༗ 100 ݸ Classɻ แؚ: NSStringEncoding, NSNumberFormatterStyle… • ྻද੥؃ SE-0086 • ᔒྻग़ိత౎။อཹ NS ։಄ • ။༗ migrator
  11. SE-0091 վਐ Protocol தత operator એࠂํࣜ //ݱࡏ struct Foo {}

    protocol Equatable { func ==(lhs: Self, rhs: Self) -> Bool } extension Foo: Equatable {} func ==(lhs: Foo, rhs: Foo) -> Bool { return lhs.value == rhs.value }
  12. SE-0091 վਐ Protocol தత operator એࠂํࣜ //ະိ protocol Equatable {

    func ==(lhs: Self, rhs: Self) -> Bool } struct Foo: Equatable { let value: Int static func ==(lhs: Foo, rhs: Foo) -> Bool { return lhs.value == rhs.value } }
  13. Evolution • SE-0112 վਐ NSError bridging • SE-0114 ሡ Buffer

    త Value վҝ Header • SE-0115 Literal protocol վ໊ • SE-0118 Closure ჩᏐվ໊
  14. SE-0112 վਐ NSError bridging • ݱ༗త NSError bridging ༗ࡾݸ໰୊ •

    ErrorProtocol ᔒ㭎๏ఏڙ userInfo • Obj-C ိత API ᔒ㭎๏፤౸ userInfo • ༗Ұࠣ NSError * ჩᏐᔒ༗᫚׵౸
  15. SE-0112 վਐ NSError bridging • ৽⃧ࡾݸErrorProtocol LocalizedError, RecoverableError, CustomNSError •

    Obj-c աိత Error ။༗ userInfo property • ೺Ⴋᰨత NSError ᫚ҝ ErrorProtocol
  16. SE-0115 Literal protocol վ໊ • *LiteralConvertible ሡ။Ꮣ੒ ExpressibleBy*Literal struct Age

    : IntegerLiteralConvertible{ var value:Int init(integerLiteral val:IntegerLiteralType){ value = val } } let turtle:Age = 100 turtle.value
  17. Evolution • SE-0101 Ҡআ sizeofɼ৽⃧ MemoryLayout • SE-0116 Obj-C API

    త id ။Import ੒ Any • SE-0120 मվ partition വᏐ • SE-0121 Ҡআ Optional తൺֱӡࢉ • SE-0124 Int.init(ObjectIdentifier) ৽⃧ bitPattern ඪត
  18. SE-0101 Ҡআ sizeofɼ৽⃧ MemoryLayout • Ҡআ sizeof, sizeofValue, alignof, alignofValue,

    strideof, strideofValue • ৽⃧ MemoryLayout • MemoryLayout.of(1).size //8
  19. SE-0116 Obj-C API త id ။Import ੒ Any • ݱࡏObj-C

    API త id ྨผੋImport ੒ AnyObjectɼ ॴҎValue త෺݅बෆೳ࢖༻ • ະိ။ Import ੒ Anyɼൺֱํศ࢖༻
  20. SE-0120 मվ partition വᏐ • ݱ༗తpartition ੋڅ partition sort ༻త

    var n = [5, 1, 2, 3, 6, 7, 8] let p = n.partition() //3 n // [3, 1, 2, 5, 6, 7, 8] • Ҡআݱ༗తɼ৽⃧partition(by:)ɼճၚᆴతࠨᬑੋ false తݩૉɼӈᬑੋ true తݩૉ var n = [5, 1, 2, 3, 6, 7, 8] let p = n.partition(by: { $0 > 2 }) // 2 n // [2, 1, 5, 3, 6, 7, 8]
  21. SE-0121 Ҡআ Optional తൺֱӡ ࢉ • Optional ݱࡏՄҎ࿨ී௨ᆴ၏ൺֱେখɼOptional Ӭԕ။খԙී௨ᆴɻ༗త࣌ީ။༗ҙ֎త݁Ռ struct

    Person{ var name:String var age:Int? } let people=[ Person(name:"John", age:29), Person(name:"Ive", age: .none) ] let kids = people.filter{$0.age<20} kids // [{name "Ive", nil}]