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

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

horimislime
November 07, 2014

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

horimislime

November 07, 2014
Tweet

More Decks by horimislime

Other Decks in Technology

Transcript

  1. 4XJGU-JCSBSZ

    ͬ͘͟Γݱঢ়֬ೝ
    4XJGU4UVEZୈճ

    View full-size slide

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

    View full-size slide

  3. 4XJGUք۾ͷࠓ
    w (JUIVCSFQPTJUPSZڧ MBOHVBHFTXJGUͰݕࡧ

    w $PDPB1PETͰͷެ։͸ະରԠ *TTVF

    w 5SFOEJOHʹ্͕͍ͬͯΔϥΠϒϥϦΛز͔ͭ঺հ͠·͢

    View full-size slide

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

    "MBNPpSF

    /FU

    4XJGU)551

    View full-size slide

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

    "MBNPpSF

    /FU

    4XJGU)551

    View full-size slide

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

    View full-size slide

  7. 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)
    }

    View full-size slide

  8. "MBNPpSF
    w ϝιουνΣΠϯͰهड़Ͱ͖Δ
    w ػೳతʹෆࣗ༝ͳͦ͞͏
    w ͪΐͬͱ͓΋͠Ζ͍ػೳ΋

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  12. 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
    }
    }

    View full-size slide

  13. 3PVUFS
    㾎 "1*FOEQPJOUͷ৘ใΛ&OVNʹด͡Δ͜ͱ͕Ͱ͖Δ
    㾎 63-؅ཧ༻Ϋϥε͸ෆཁʹ
    㾎 #MPH"QJTXJGUΈ͍ͨͳΫϥε΋ແͤͦ͘͏

    View full-size slide

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

    4XJGUZ+40/

    +40/)FMQFS

    0CKFDU.BQQFS

    View full-size slide

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

    4XJGUZ+40/

    +40/)FMQFS

    0CKFDU.BQQFS

    View full-size slide

  16. Alamofire.request(.GET, "http://api.example.com/user/horimi/entry/1234")
    .responseSwiftyJSON { (request, response, json, error) in
    println(json) // => JSON type
    }

    View full-size slide

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

    View full-size slide

  18. 9$(-PHHFS
    w ϩάϨϕϧ͕ଘࡏ͢Δ EFCVH JOGP FSSPS

    w 4IBSFEJOTUBODFʹରͯ͠ઃఆ͕Մೳ

    ྫQSPEͳΒϩάΛు͖ग़͞ͳ͍
    w ϑΝΠϧॻ͖ग़͠ʹ΋ରԠ͍ͯ͠Δ

    View full-size slide

  19. 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
    }
    ...
    }

    View full-size slide

  20. 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
    }

    View full-size slide

  21. var outputLogLevel: XCGLogger.LogLevel = .Debug
    func isEnabledForLogLevel (logLevel: XCGLogger.LogLevel) -> Bool {
    return logLevel >= self.outputLogLevel
    }

    View full-size slide

  22. ΍ͬͺ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

    View full-size slide

  23. public class XCGConsoleLogDestination : XCGLogDestinationProtocol, DebugPrintable {

    public func processLogDetails(logDetails: XCGLogDetails) {

    var fullLogMessage: String = “…”
    dispatch_async(XCGLogger.logQueue) {
    print(fullLogMessage)
    }
    }
    }

    View full-size slide

  24. ग़ྗઌΧελϚΠζՄೳ
    w ίϯιʔϧग़ྗ͸9$($POTPMF-PH%FTUJOBUJPO͕୲౰

    MPHCBDLͷ$POTPMF"QQFOEBS
    w 9$(-PH%FTUJOBUJPO1SPUPDPMΛ࣮૷͢Ε͹

    ΧελϜͷग़ྗઌ͕࣮ߦͰ͖Δ
    w )551ӽ͠ʹϩάΛૹΔ͜ͱ΋Ͱ͖ͦ͏ USBDLJOHͱ͔

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. 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)
    }
    }
    }
    }

    View full-size slide

  28. ·ͱΊ
    w 4XJGUք۾ͷݱঢ়ɾؾʹͳΔϥΠϒϥϦ঺հ
    w ಺෦࣮૷΍࢖͍ํʹ͍ͭͯ
    w બఆ͚ͩͰͳ͘ɺ಺෦࣮૷ݟΔͱֶͼଟ͍ͷͰੋඇʂ

    View full-size slide

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

    View full-size slide

  30. ࢀߟ
    w 4XJGUZ+40/4XJGUZ+40/
    w JTBJS+40/)FMQFS
    w %BWF8PPE$PN9$(-PHHFS
    w 4XJGU4UBOEBSE-JCSBSZ3FGFSFODF$PNQBSBCMF
    w 2VJDL2VJDL

    View full-size slide