Safer Networking Layer With Swift

Safer Networking Layer With Swift

562e29ba057361b2b944bd7bbd274887?s=128

Yusei Nishiyama

July 14, 2015
Tweet

Transcript

  1. 4BGFS /FUXPSLJOH -BZFSXJUI 4XJGU

  2. 8IPBN* w :VTFJ/JTIJZBNB !ZVTFJOJTIJZBNB  w J04EFWFMPQFS ZFBST w $PPLQBE

    w *OUFSOBUJPOBMHSPVQ w -FBSOJOH&OHMJTI
  3. (MPCBM

  4. 1MFBTFGPSHJWFNF

  5. 5IJTJTB3VCZ NFFUVQ

  6. #VU*`Nʜ wXPSLJOHGPSBOJ04 BQQMJDBUJPO w*IBWFWFSZMJUUMF FYQFSJFODFPG3BJMT 3VCZBTXFMM

  7. "T"NPCJMF EFWFMPQFS *XBOU ZPVUPLOPXBCPVUʜ

  8. 4XJGU

  9. 8IZTIPVMEXF VTF4XJGU

  10. [CKDPantrymanInitializer setVariables]; [[CKDPushNotificationManager sharedManager] start]; [[CKDPushNotificationManager sharedManager] registerForRemoteNotification]; [[CKDBargainManager sharedManager]

    start]; [[CKDDeviceTrackingManager sharedManager] start]; [[CKDInitializeConfigManager sharedManager] start]; [[CKDSupportContactsManager sharedManager] start]; [[CKDAccountManager sharedManager] migrateStoredAccount]; [[CKDGoogleAnalyticsManager sharedManager] startTracking]; [[CKDHistoryManager sharedManager] load]; [[CKDRecipesManager sharedManager] load]; #FDBVTFPG0CKFDUJWF$ TZOUBY /P JU`TOPU
 4FFUIFHFPNFUSJDCFBVUZ
  11. 0CKFDUJWF$JTMJLF3VCZ wEZOBNJDEJTQBUDI wEZOBNJDUZQJOH wSFqFDUJPONFUIPET wSVOUJNFIBDLFSZ

  12. 1SPT w-FTTWFSCPTF w:PVDBOTFFZPVSSFTVMU JNNFEJBUFMZ w'BTURVJDLEFWFMPQNFOU DZDMFTBOEQSPUPUZQJOH

  13. 1SPT NSArray *array = @[[Recipe new]]; BOOL boolValue = [array[0]

    boolValue]; :PVDBOEPBOZUIJOHZPVXBOUUP 4VQFSC name = "John" name = Time.now() name = 123.45
  14. None
  15. $POT w$SBTIFTPOl3VOUJNFz w1PPSQFSGPSNBODF w1PPSJOUFHSBUJPOXJUI *%&T

  16. 8PSLJOHPOJ04

  17. 8FIBWFUIFQSFUUZ OJDFQBSUOFS You can’t release such a crap! Wait until

    I finish reviewing There are no exceptions
  18. None
  19. None
  20. http://appreviewtimes.com/

  21. J040CKFDUJWF$ w&SSPSQSPOF w)BSEUPSFDPWFS

  22. .BLFFWFSZUIJOH NPSFSFMJBCMF

  23. 4XJGU

  24. 4XJGU w5ZQFTBGF w/VMMTBGF w:PVDBOpOETPNFUIJOH XSPOHPOlDPNQJMF UJNFz

  25. /FUXPSLJOH

  26. *O0CKFDUJWF$ NSDictionary *parameters = @{ @"page": @(page), @"per_page": @10, };

    [client requestGetWithPath:path parameters:parameters completion:^(NSArray *recipes, NSError *error) { if (nil == error) { } else { } }]; There are 4 possibilities The type of response is determined dynamically SFDJQFTOJM SFDJQFTOJM FSSPSOJM GBJMVSF FSSPSOJM TVDDFTT
  27. *O4XJGU let params = PaginationParams(order: .Desc(field: .Publish), page: 1, perPage:

    10) let api = APIs.Recipes.Get(paginationParams: params) SharedAPIClient.sendRequest(api) { response in switch response { case .Success(let value): value[0].cookingTime case .Failure(let value): value.message } } The type of the response can be determined statically You can handle success and failure exhaustively
  28. &OVN enum Order : Printable { enum Field: Printable {

    case Update, Publish var description: String { switch self { case .Update: return "updated_at" case .Publish: return "published_at" } } } case Desc(field: Field), Asc(field: Field) var description: String { switch self { case .Desc(let field): return "\(field)_desc" case .Asc(let field): return "\(field)_asc" } } } Enum can conform protocols Enum can have properties and functions You can associate a value with an enum let params = PaginationParams(order: .Desc(field: .Publish), page: 1, perPage: 10)
  29. 1SPUPDPM protocol API { typealias ResponseType class Recipes { class

    Get: API { typealias ResponseType = PagedRecipes Associated Types A type conform the protocol can determine an actual type
  30. (FOFSJDT func sendRequest<T: API>(API: T, handler: (T.ResponseType) -> Void) Generic

    functions Associated Types
  31. &JUIFS public enum Result<T, E> { case Success(T) case Failure(E)

    } Generics Enum with associated value
  32. /VMMBCJMJUZ  *NNVUBCJMJUZ struct Recipe { var id: Int? var

    title = "" let user: User This can be nil This is immutable This can’t be nil and has default value This can’t be nil
  33. 1VUFWFSZUIJOHUPHFUIFS let params = PaginationParams(order: .Desc(field: .Publish), page: 1, perPage:

    10) let api = APIs.Recipes.Get(paginationParams: params) SharedAPIClient.sendRequest(api) { response in switch response { case .Success(let value): value[0].cookingTime case .Failure(let value): value.message } } Enum Nested Classes Either Associated Value Protocol With Associated Type
  34. 4VNNBSZ

  35. w0CKFDUJWF$˺3VCZ w0CKFDUJWF$4XJGU w3VCZ4XJGU w4XJGUNBLFTZPVS BQQMJDBUJPOTSFMJBCMF

  36. None
  37. *T4XJGU QSPEVDUJPO RVBMJUZ 

  38. 0GDPVSTF w0VS JOUFSOBUJPOBM J04 BQQMJDBUJPODPOTJTUTPG 4XJGU w*SFXSPUFBMNPTUPGUIF 0CKFDUJWF$DPEFJOUP 4XJGUPSNPOUIBHP

  39. ૣ͘͠Ζ Hurry up! Date prisa! اولجع! Cepatlah!

  40. 8FBSFIJSJOH

  41. "OZRVFTUJPOT