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

Swift 周報 4/12

Swift 周報 4/12

Swift 周報 4/12

Johnlin

April 12, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Evolution • SE-0042 ἷฏԽ instance method references తܕผ • SE-0043

    ࡏ༗ଟݸpatterns త case label தએࠂᏓ Ꮠ • SE-0044 Import C function ᗣ swift function • SE-0047 ༬ઃܯࠂᔒ༗࢖༻౸తճၚᆴ
  2. ἷฏԽ instance method references తܕผ • ݱࡏ class Foo {

    func foo(bar:Int) { print(bar) } } Foo.foo(Foo())(3) // 3 • ະိ Foo.foo(Foo(),3) // 3
  3. ࡏ༗ଟݸpatterns త case label தએࠂᏓᏐ • Լ໘Ҏޙ။ಈ let point =

    (2,2) switch point { case let (1,x), let (2,x): //error print(x) default: break }
  4. Import C function ᗣ swift function • ݱࡏimport C function

    ޙ။Ꮣ੒global function • ະိՄҎࢦఆimport ਐိޙతҐஔɼ໵बੋՄҎࢦఆC function ੒ᗣ init, method, computed property, static property, static computed property ҃ੋ subscript • ࢖༻ __attribute__((swift_name(“SWIFT_NAME")));
  5. Import C function ᗣ swift function // Import as init

    struct Point3D createPoint3D(float x, float y, float z) __attribute__((swift_name("Point3D.init(x:y:z:)"))); // Import as method struct Point3D rotatePoint3D(Point3D point, float radians) __attribute__((swift_name("Point3D.rotate(self:radians:)")));
  6. ༬ઃܯࠂᔒ༗࢖༻౸తճၚᆴ • ᙛfunc ༗ճၚᆴɼୠੋᔒ༗ඃ༻౸త࣌ީሡ။༬ઃग़ݱܯࠂ func getScore()->Int { return 56 }

    var score = 0 getScore() //will raise warning print(score) • ݱࡏ༬ઃෆ။ܯࠂɼ༻@warn_unused_result ՄҎ㗞ੜܯ ࠂɻ • ະိ༬ઃܯࠂɼՄҎ༻@discardableResult ိऔফܯࠂɻ
  7. Evolution • SE-0016 Unsafe[Mutable]Pointer ՄҎ᫚੒ Int • SE-0053 function ჩᏐதෆ࠶ՄҎ༗

    let • SE-0054 Abolish ImplicitlyUnwrappedOptional type • SE-0055 ᩋUnsafe Pointer໵࢖༻Optional ိදࣔ nullability
  8. function ჩᏐதෆ࠶ՄҎ༗ let • function ჩᏐ໨લpass by value ޙ౎ੋෆೳվᏓతɼະ ိ။׬શෆೳࡏჩᏐલ໘ଧ

    let/var fun fLet(let a:Int) { print(a) } • ޷႔ɿະိ argument label ՄҎੋ೚Կ keyword func fc(let l:Int) { print(l) } fc(let: 10)
  9. ᩋUnsafe Pointer໵࢖༻Optional ိ දࣔ nullability • ݱࡏᔒ༗㭎๏ኺType ؃ग़Pointer ༗ᔒ༗Մೳੋ NULL

    • ະိ Pointer ໵။Ճೖ Optional తޭೳ • if let ptr = nil_ptr {
 foo(ptr)
 }