Save 37% off PRO during our Black Friday Sale! »

Swift Libraryざっくり現状確認 / Swift library overview

503b1ca28b167b0d94a5992aad1a57b1?s=47 horimislime
November 07, 2014

Swift Libraryざっくり現状確認 / Swift library overview

503b1ca28b167b0d94a5992aad1a57b1?s=128

horimislime

November 07, 2014
Tweet

Transcript

  1. 4XJGU-JCSBSZ
 ͬ͘͟Γݱঢ়֬ೝ 4XJGU4UVEZୈճ

  2. ಺༰ w 4XJGUϥΠϒϥϦք۾ͷಈ޲ʹ͍ͭͯ w ͙͢׆༻Ͱ͖ͦ͏ͳ΋ͷΛϐοΫΞοϓ w ಺෦࣮૷΍࢖͍ํͰؾʹͳͬͨͱ͜ΖΛ঺հ

  3. 4XJGUք۾ͷࠓ w (JUIVCSFQPTJUPSZڧ MBOHVBHFTXJGUͰݕࡧ  w $PDPB1PETͰͷެ։͸ະରԠ *TTVF  w

    5SFOEJOHʹ্͕͍ͬͯΔϥΠϒϥϦΛز͔ͭ঺հ͠·͢
  4. )551௨৴

  5. )551ϥΠϒϥϦ w 0CK$࣌୅ɿ"'/FUXPSLJOH w 4XJGU࣌୅ɿ
 "MBNPpSF
 /FU
 4XJGU)551

  6. )551ϥΠϒϥϦ w 0CK$࣌୅ɿ"'/FUXPSLJOH w 4XJGU࣌୅ɿ
 "MBNPpSF
 /FU
 4XJGU)551

  7. Alamofire.request(.GET, "http://api.example.com/user/horimi") .responseString { (request, response, string, error) in println(request)

    println(response) println(string) }
  8. Alamofire.request(.GET, "http://api.example.com/user/horimi")
 .validate(statusCode: 200...<300)
 .validate(contentType: [“application/json”]) .responseString { (request, response,

    string, error) in println(request) println(response) println(string) }
  9. "MBNPpSF w ϝιουνΣΠϯͰهड़Ͱ͖Δ w ػೳతʹෆࣗ༝ͳͦ͞͏ w ͪΐͬͱ͓΋͠Ζ͍ػೳ΋

  10. GET api.example.com/user/horimi/entry/1234

  11. GET api.example.com/user/horimi/entry/1234

  12. Alamofire.request(.GET, ApiRouter.Entry("horimi", 1234))

  13. enum ApiRouter: URLStringConvertible { static let baseURLString = "http://api.example.com" case

    User(String) case Entry(String, Int) var URLString: String { let path: String = { switch self { case .User(let userId): return "/user/\(userId)" case .Entry(let userId, let entryId): return "/user/\(userId)/entry/\(entryId)/" } }() return ApiRouter.baseURLString + path } }
  14. 3PVUFS 㾎 "1*FOEQPJOUͷ৘ใΛ&OVNʹด͡Δ͜ͱ͕Ͱ͖Δ 㾎 63-؅ཧ༻Ϋϥε͸ෆཁʹ 㾎 #MPH"QJTXJGUΈ͍ͨͳΫϥε΋ແͤͦ͘͏

  15. +40/"1*ͱͷ࿈ܞ w %JDUJPOBSZΛੜͰѻ͏͜ͱΛආ͚Δ w +BWBͷ0CKFDU.BQQFSతͳࣄ w ݁ߏͨ͘͞Μग़ͯΔ
 4XJGUZ+40/
 +40/)FMQFS
 0CKFDU.BQQFS

  16. +40/"1*ͱͷ࿈ܞ w %JDUJPOBSZΛੜͰѻ͏͜ͱΛආ͚Δ w +BWBͷ0CKFDU.BQQFSతͳࣄ w ݁ߏͨ͘͞Μग़ͯΔ
 4XJGUZ+40/
 +40/)FMQFS
 0CKFDU.BQQFS

  17. Alamofire.request(.GET, "http://api.example.com/user/horimi/entry/1234") .responseSwiftyJSON { (request, response, json, error) in println(json)

    // => JSON type }
  18. "MBNPpSF 4XJGUZ+40/ ϨεϙϯεΛࣗಈతʹ4XJGUZ+40/ͷܕʹ੔͑ͯ͘ΕΔ ೚ҙͷϞσϧʹϚοϓ͢Δͷ͸ࣗલͰ 4XJGUͷ࢓্༷+BDLTPOΈ͍ͨͳࣄΛ͢Δͷ͸ݫͦ͠͏

  19. 6UJMJUJFT

  20. 9$(-PHHFS w ϩάϨϕϧ͕ଘࡏ͢Δ EFCVH JOGP FSSPS  w 4IBSFEJOTUBODFʹରͯ͠ઃఆ͕Մೳ
 ྫQSPEͳΒϩάΛు͖ग़͞ͳ͍

    w ϑΝΠϧॻ͖ग़͠ʹ΋ରԠ͍ͯ͠Δ
  21. let log = XCGLogger.defaultInstance() @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { log.setup(logLevel: .Debug, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil) log.info("Initialized") return true } ... }
  22. public enum LogLevel: Int, Comparable { case Verbose case Debug

    case Info case Error case Severe case None } public func < (lhs:XCGLogger.LogLevel, rhs:XCGLogger.LogLevel) -> Bool { return lhs.rawValue < rhs.rawValue }
  23. var outputLogLevel: XCGLogger.LogLevel = .Debug func isEnabledForLogLevel (logLevel: XCGLogger.LogLevel) ->

    Bool { return logLevel >= self.outputLogLevel }
  24. ΍ͬͺ4XJGUͷ&OVNྑ͍ w &OVNΛൺֱՄೳʹ
 ೥ྸɺϨϕϧ౳ͷσʔλͰ
 ࢖͑ͦ͏ w DBTFͷॱ൪ʹ͸஫ҙ
 SBX7BMVF+BWBͷPSEJOBM 
 ҙຯ͕খ͍͞ॱʹྻڍ͢Δ

    w   ͦΕͧΕʹϝιου͕ඞཁ
 ౳Ձԋࢉ͸&RVBUBCMFQSPUPDPM enum Size: Int, Comparable { case Large case Medium case Small } func < (l:Size, r:Size) -> Bool { return l.rawValue < r.rawValue } var flag = Size.Small < Size.Large // => false
  25. public class XCGConsoleLogDestination : XCGLogDestinationProtocol, DebugPrintable { … public func

    processLogDetails(logDetails: XCGLogDetails) { … var fullLogMessage: String = “…” dispatch_async(XCGLogger.logQueue) { print(fullLogMessage) } } }
  26. ग़ྗઌΧελϚΠζՄೳ w ίϯιʔϧग़ྗ͸9$($POTPMF-PH%FTUJOBUJPO͕୲౰
 MPHCBDLͷ$POTPMF"QQFOEBS w 9$(-PH%FTUJOBUJPO1SPUPDPMΛ࣮૷͢Ε͹
 ΧελϜͷग़ྗઌ͕࣮ߦͰ͖Δ w )551ӽ͠ʹϩάΛૹΔ͜ͱ΋Ͱ͖ͦ͏ USBDLJOHͱ͔

  27. 5FTU

  28. 2VJDL w #%%ͳςετϑϨʔϜϫʔΫ w 9$5FTUΑΓߴ͍Մಡੑ w ςετϑϨʔϜϫʔΫͳͷͰΧδϡΞϧʹࢼͤΔ

  29. func testGetUserSuccess() { XCTAssertNotNil(User.get("horimi")) XCTAssertNil(User.get("vavavavavava")) }

  30. class UserSpec: QuickSpec { override func spec() { describe("User") {

    it("should exist") { expect(User("horimi")).notTo(nil) } it("should not exist") { expect(User.get("vavavavava")).to(nil) } } } }
  31. ·ͱΊ w 4XJGUք۾ͷݱঢ়ɾؾʹͳΔϥΠϒϥϦ঺հ w ಺෦࣮૷΍࢖͍ํʹ͍ͭͯ w બఆ͚ͩͰͳ͘ɺ಺෦࣮૷ݟΔͱֶͼଟ͍ͷͰੋඇʂ

  32. ࢀߟ w 5SFOEJOH4XJGUSFQPTJUPSJFTPO(JU)VCUIJTNPOUI w 'JSTUQIBTFUPXBSET$MBOH.PEVMFT'SBNFXPSLTu *TTVFu$PDPB1PET$PDPB1PET w "MBNPpSF"MBNPpSF w OHIJBMW/FU

    w EBMUPOJBN4XJGU)551
  33. ࢀߟ w 4XJGUZ+40/4XJGUZ+40/ w JTBJS+40/)FMQFS w %BWF8PPE$PN9$(-PHHFS w 4XJGU4UBOEBSE-JCSBSZ3FGFSFODF$PNQBSBCMF w

    2VJDL2VJDL