This repository has been archived by the owner on May 17, 2024. It is now read-only.
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.
Previously Mapper worked by conditionally downcasting values to the
expected types. For example:
Would basically translate to:
This worked perfectly for many common types, such as
String
andInt
.But this became a problem when you used types that could not be
converted like this such as
NSDate
. Previously this line of code wouldcompile without any additions to Mapper:
But since this would translate to:
This would fail 100% of the time. But since it compiled it would leave
callers assuming that it could work. This is no longer the case. Now if
you attempt to cast to a type that doesn't conform to
Convertible
(unless it's
RawRepresentable
or you're using a transformation) itwill fail to compile.
There are some adverse side effects of this change. For one, you can no
longer map to
AnyObject
[AnyObject]
or[String: AnyObject]
. Thisis because if we made
AnyObject
conform toDefaultConvertible
wewould be in the same place we were before with the
NSDate
examplecompiling, even though it shouldn't. The alternative in the latter 2
cases is to use
NSArray
andNSDictionary
respectively. After you mapto those, you could then map them back to the Swift types if it was
necessary. Another possible solution for all 3 cases is to create a
transformation that returns these types using
as?
. This way you won'tbreak the compile time safety for all other types, but you can still get
the types using
AnyObject
back.