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

Swift weekly 8/16

Johnlin
August 16, 2016

Swift weekly 8/16

Johnlin

August 16, 2016
Tweet

More Decks by Johnlin

Other Decks in Programming

Transcript

  1. Evolution • SE-0117 ე෼ެ։࿨Մ៺ঝ • SE-0125 ҠআNonObjectiveCBase ࿨ isUniquelyReferenced •

    SE-0127 ߋ৽ stdlib தᢛPointer ࿨ Buffer ૬᮫വᏐ • SE-0128 UnicodeScalar తfailable ݐߏࣜ
  2. SE-0117 ე෼ެ։࿨Մ៺ঝ • ໨લSwift ༗ҎԼزछᒟݶ᮫伴ࣈ • private : ୞༗ಉҰݸ䈕Ҋ㚎ՄҎ࢖༻ •

    internal : ୞༗ಉҰݸModule (target) 㚎ՄҎ࢖༻ • public : ଖଞత Module ໵ՄҎ࢖༻ • final : ෆೳⴺ៺ঝ҃ override
  3. SE-0117 ე෼ެ։࿨Մ៺ঝ • ৽⃧Ұݸ open ᒟݶ᮫伴ࣈɼ૬ᙛԙݱࡏత public ᮫伴ࣈɻ • public

    ᮫伴ࣈత։์ఔ౓ሡ߱௿ɼ୞ೳⴺ࢖༻ɼୠ ੋෆೳ៺ঝ҃override • ؆ᄸိ㘸बੋ༬ઃෆೳ៺ঝ҃overrideɻ
  4. SE-0117 ე෼ެ։࿨Մ៺ঝ //ผతModule㚎ෆೳⴺὺӵđᆺି൐Ⴈ public class publicClass{ //ࡏผతModule 㚎ෆೳ override public

    func foo() {} //ࡏผతModule 㚎ෆೳ overrideɼ Ҽҝclass ෆੋ open open func bar() {} //ࡏಉҰݸ Module 㚎໵ෆೳ override public final func baz() {} }
  5. SE-0117 ე෼ެ։࿨Մ៺ঝ //ผతModule 㚎ՄҎ៺ঝ open class openClass{ // ผత Module㚎ෆೳ

    override public var count:Int // ผత Module㚎ෆೳ override public func foo(){} // ผత Module㚎ՄҎ override open func bar(){} //ࡏಉҰݸ Module 㚎໵ෆೳ override public final func baz() {} }
  6. SE-0125 ҠআNonObjectiveCBase ࿨ isUniquelyReferenced • NonObjectiveCBase Class ੋ༻ိඪࣔෆੋObj-C Class త

    Base Class • isUniquelyReferenced ՄҎ༻ိ֬ೝ NonObjectiveCBase త Object ੋෆੋ୞༗Ұݸᘐಛ త Reference
  7. SE-0125 ҠআNonObjectiveCBase ࿨ isUniquelyReferenced • ୠੋ isUniquelyReferencedNonObjC ఏڙҰᒬతᏈ Ռɼࣕ׌ෆध៺ঝ NonObjectiveCBase

    • Ҡআ NonObjectiveCBase & isUniquelyReferencedɼ ฒሡisUniquelyReferencedNonObjC վ໊੒ isKnownUniquelyReferenced
  8. SE-0127 ߋ৽ stdlib தᢛPointer ࿨ Buffer ૬᮫വᏐ • withUnsafePointer ৽⃧

    to: ඪត • Ҡআ withUnsafePointers വᏐ • Ҡআ unsafeAddress(of:) ՄҎվ༻ ObjectIdentifier(obj).unsafeAddress • Ҡআ ManagedProtoBuffer Class
  9. SE-0128 UnicodeScalar తfailable ݐߏࣜ ݱࡏ
 var string = "" let

    codepoint: UInt32 = 55357 // ແᏈతcodepoint let ucode = UnicodeScalar(codepoint) // രᖵ string.append(ucode)
  10. SE-0128 UnicodeScalar తfailable ݐߏࣜ ະိ
 var string = "" let

    codepoint: UInt32 = 55357 // ແᏈతcodepoint if let ucode = UnicodeScalar(codepoint) { string.append(ucode) }
  11. Evolution • SE-0129 ߋ৽౟݅؅ཧثతଌࢼ໋໊׳ྫ • SE-0130 ڧԽ String(repeating:, count:) API

    • SE-0131 ৽⃧ AnyHashable • SE-0133 flatten վ໊ҝ joined • SE-0134 मվၷݸ UTF8 ૬᮫త String property
  12. SE-0129 ߋ৽౟݅؅ཧثతଌࢼ ໋໊׳ྫ • ॴ༗ࡏ Tests/ ࢿྉᇄதత *Tests ౎။ඃᙛ੒ Test

    Module • FooTests ။ࣗಈ࿨ Foo Module 㗞ੜ᮫࿆ • Tests/ ࢿྉᇄத೗Ռ༗ࣥߦ䈕။ඃࢹҝࡨޡ • Sources/ ࢿྉᇄத೗Ռ༗ଌࢼ။ඃࢹҝࡨޡ
  13. SE-0130 ڧԽ String(repeating:, count:) API • ݱࡏ let x =

    String(repeating:"5", count: 6) // ࡨޡ let x = String(repeating:"5" as UnicodeScalar , count: 6) // "555555" let x = String(repeating:"5" as Character , count: 6) // "555555" • ະိ let x = String(repeating:"5", count: 6) // lz let x = String(repeating:"5" as UnicodeScalar , count: 6) // ࡨޡ let x = String(repeating:"5" as Character , count: 6) // ࡨޡ
  14. SE-0131 ৽⃧ AnyHashable • ݱࡏ NSDictionary ။ඃაೖ੒
 [NSObject : AnyObject]

    • ະိ။ඃაೖ੒ [AnyHashable : Any] • AnyHashable ੋҰݸ९॥ Equatable ࿨ Hashable త Struct
  15. SE-0133 flatten վ໊ҝ joined • ݱࡏ [[1,2],[3]].flatten() // [1,2,3] [[1,2],[3]].joined(separator:

    []) // [1,2,3] [[1,2],[3]].joined(separator: [0]) // [1,2,0,3] [[1,2],[3]].joined() // ࡨޡ • ະိ [[1,2],[3]].joined() // [1,2,3] [[1,2],[3]].joined(separator: []) // [1,2,3] [[1,2],[3]].joined(separator: [0]) // [1,2,0,3] [[1,2],[3]].flatten() // ࡨޡ
  16. SE-0135 ౟݅؅ཧثሣෆಉSwfit ൛ຊత૬༰ੑ • ౟݅؅ཧث။ಁաgit tag ҃ Package.swift ိࣗಈఁଌࢧ ԉత

    Swift ൛ຊ • LibFoo త 1.5 ൛ɼ ೗ՌࡏෆಉతBranch ಉ࣌ࢧԉ 2.3 ࿨ 3.0 ൛త Swiftɻ ҰݸతGit Tag ။ੋ [email protected] ɼ㠥Ұ ݸ။ੋ [email protected] • ҃ੋࡏಉҰݸBranch ্ɼҰݸ࢖༻ [email protected] 㠥Ұݸ࢖༻ [email protected]
  17. SE-0136 sizeofValue ෮׆ • ೭લ SE-0101 ೺sizeof Ҡআɻ • ޙိᚙݱؐੋ༗ඞཁ

    • ॴҎҎԼతfunction ෮׆ྃ • MemoryLayout.size(ofValue: x)
 MemoryLayout.stride(ofValue: x)
 MemoryLayout.alignment(ofValue: x)