Top Banner
Consuming API The Good, the Bad and the Ugly
26
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: [CocoaHeads Tricity] Michał Zygar - Consuming API

Consuming API The Good, the Bad and the Ugly

Page 2: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 3: [CocoaHeads Tricity] Michał Zygar - Consuming API

Easy!

Page 4: [CocoaHeads Tricity] Michał Zygar - Consuming API

Don’t reinvent the wheelUse libraries!

Page 5: [CocoaHeads Tricity] Michał Zygar - Consuming API

Can we improve it?

• Not reusable

• What if there is some authorization?

• Common error handling?

Page 6: [CocoaHeads Tricity] Michał Zygar - Consuming API

API ManagerACHIEVEMENT UNLOCKED

Page 7: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 8: [CocoaHeads Tricity] Michał Zygar - Consuming API

Data (de)serializationACHIEVEMENT UNLOCKED

Page 9: [CocoaHeads Tricity] Michał Zygar - Consuming API

Creating objects from JSON

[User userWithDictionary:(NSDictionary*)dict]

[UserFactory createUserWithDictionary:(NSDictionary*)dict]

Page 10: [CocoaHeads Tricity] Michał Zygar - Consuming API

Alternatives

• KZPropertyMapper • Mantle • JSONModel

Page 11: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 12: [CocoaHeads Tricity] Michał Zygar - Consuming API

Let’s just paste the new parsing code everywhere, or….

Page 13: [CocoaHeads Tricity] Michał Zygar - Consuming API

Abstraction is nice

Page 14: [CocoaHeads Tricity] Michał Zygar - Consuming API

Abstraction is nice

Page 15: [CocoaHeads Tricity] Michał Zygar - Consuming API

Abstraction is nice

• Network engine independent

• Easy to use

• Extendable

Page 16: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 17: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 18: [CocoaHeads Tricity] Michał Zygar - Consuming API

Categories to the rescue!

Page 19: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 20: [CocoaHeads Tricity] Michał Zygar - Consuming API

SWIFT

Page 21: [CocoaHeads Tricity] Michał Zygar - Consuming API

ALAMOFIREis the new AFNetworking

Page 22: [CocoaHeads Tricity] Michał Zygar - Consuming API

Easy!

Page 23: [CocoaHeads Tricity] Michał Zygar - Consuming API

More complicated is more complicated*

* - If you are begginer in swift

Page 24: [CocoaHeads Tricity] Michał Zygar - Consuming API
Page 25: [CocoaHeads Tricity] Michał Zygar - Consuming API

ashfurrow/Moya

Page 26: [CocoaHeads Tricity] Michał Zygar - Consuming API

Thanks!

@mzygar