Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Parsing improvements to LKAPI!
All (probably) data models that are serialized from JSON data (now represented as
ModelDict
; Use it, it's way easier to type than[String: AnyObject]
) should respond to theModelType
protocol.This will cause all models to get the static
parse
function that will initialize (withdata: ModelDict
) that type by default, and will need to create an initializer to handle the JSON datainit(data: ModelDict)
.Here's where this gets awesome. No more
if let
s to serialize data into your models! Instead, use the parse function on the dictionary! There's three versions of the function:parse<T>(key: String, or fallback: T) -> T
- Use this for primitive types. So to parse the id from a dictionary with the default of0
useid = dict.parse("id", or 0)
parse<T where T: Parseable>(key: String, type: T.Type) -> T?
- Use this for parsing anAnyObject
to aParseable
type. So if you want to convert a date string into a date, create a parseable extension on NSDate and defineparse(data: AnyObject) -> Parseable?
that converts the string to an NSDate.parse<T where T: ModelType>(type: T.Type) -> T?
- Use this to parse a dictionary to a ModalTypePlease checkout the
ParsingTests.swift
file for a bunch of examples on how to use the new parsing improvements.