0001    import Foundation
0002    
0003    /**
0004     Mapper creates strongly typed objects from a given NSDictionary based on the mapping provided by implementing
0005     the Mappable protocol (see `Mappable` for an example).
0006     */
0007    public struct Mapper
Mappable.swift:28
    init(map: Mapper) throws
Mappable.swift:54
        return try? self.init(map: Mapper(JSON: JSON))
Mappable.swift:60
            return try? array.map { try self.init(map: Mapper(JSON: $0)) }
Mapper.swift:149
            return try T(map: Mapper(JSON: JSON))
Mapper.swift:173
            return try JSON.map { try T(map: Mapper(JSON: $0)) }
Transform+Dictionary.swift:60
                let model = try T(map: Mapper(JSON: object))
{ 0008 private let JSON
Mapper.swift:17
        self.JSON = JSON
Mapper.swift:365
        return field.isEmpty ? self.JSON : self.JSON.valueForKeyPath(field)
Mapper.swift:365
        return field.isEmpty ? self.JSON : self.JSON.valueForKeyPath(field)
: NSDictionary 0009 0010 /** 0011 Create a Mapper with a NSDictionary to use as source data 0012 0013 - parameter JSON: The dictionary to use for the data 0014 */ 0015 @warn_unused_result 0016 public init
Mappable.swift:54
        return try? self.init(map: Mapper(JSON: JSON))
Mappable.swift:60
            return try? array.map { try self.init(map: Mapper(JSON: $0)) }
Mapper.swift:149
            return try T(map: Mapper(JSON: JSON))
Mapper.swift:173
            return try JSON.map { try T(map: Mapper(JSON: $0)) }
Transform+Dictionary.swift:60
                let model = try T(map: Mapper(JSON: object))
(JSON: NSDictionary) { 0017 self.JSON = JSON 0018 } 0019 0020 // MARK: - T 0021 0022 /** 0023 Get a typed value from the given key in the source data 0024 0025 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0026 data set 0027 0028 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to T 0029 0030 - returns: The value for the given key, if it can be converted to the expected type T 0031 */ 0032 @warn_unused_result 0033 public func from
Mapper.swift:51
        return try? self.from(field)
Mapper.swift:65
            if let value: T = try? self.from(field) {
<T>(field: String) throws -> T { 0034 if let value = self.JSONFromField(field) as? T { 0035 return value 0036 } 0037 0038 throw MapperError() 0039 } 0040 0041 /** 0042 Get an optional typed value from the given key in the source data 0043 0044 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0045 data set 0046 0047 - returns: The value for the given key, if it can be converted to the expected type T otherwise nil 0048 */ 0049 @warn_unused_result 0050 public func optionalFrom<T>(field: String) -> T? { 0051 return try? self.from(field) 0052 } 0053 0054 /** 0055 Get an optional value from the given keys and source data. This returns the first non-nil value produced 0056 in order based on the array of fields 0057 0058 - parameter fields: The array of fields to check from the source data. 0059 0060 - returns: The first non-nil value to be produced from the array of fields, or nil if none exist 0061 */ 0062 @warn_unused_result 0063 public func optionalFrom<T>(fields: [String]) -> T? { 0064 for field in fields { 0065 if let value: T = try? self.from(field) { 0066 return value 0067 } 0068 } 0069 0070 return nil 0071 } 0072 0073 // MARK: - T: RawRepresentable 0074 0075 /** 0076 Get a RawRepresentable value from the given key in the source data 0077 0078 This allows you to transparently create instances of enums and other RawRepresentables from source data 0079 0080 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0081 data set 0082 0083 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to T 0084 0085 - returns: The value for the given key, if it can be converted to the expected type T 0086 */ 0087 @warn_unused_result 0088 public func from
Mapper.swift:110
        return try? self.from(field)
Mapper.swift:124
            if let value: T = try? self.from(field) {
<T: RawRepresentable>(field: String) throws -> T { 0089 if let rawValue = self.JSONFromField(field) as? T.RawValue, 0090 let value = T(rawValue: rawValue) 0091 { 0092 return value 0093 } 0094 0095 throw MapperError() 0096 } 0097 0098 /** 0099 Get an optional RawRepresentable value from the given key in the source data 0100 0101 This allows you to transparently create instances of enums and other RawRepresentables from source data 0102 0103 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0104 data set 0105 0106 - returns: The value for the given key, if it can be converted to the expected type T otherwise nil 0107 */ 0108 @warn_unused_result 0109 public func optionalFrom<T: RawRepresentable>(field: String) -> T? { 0110 return try? self.from(field) 0111 } 0112 0113 /** 0114 Get an optional value from the given keys and source data. This returns the first non-nil value produced 0115 in order based on the array of fields 0116 0117 - parameter fields: The array of fields to check from the source data. 0118 0119 - returns: The first non-nil value to be produced from the array of fields, or nil if none exist 0120 */ 0121 @warn_unused_result 0122 public func optionalFrom<T: RawRepresentable>(fields: [String]) -> T? { 0123 for field in fields { 0124 if let value: T = try? self.from(field) { 0125 return value 0126 } 0127 } 0128 0129 return nil 0130 } 0131 0132 // MARK: - T: Mappable 0133 0134 /** 0135 Get a Mappable value from the given key in the source data 0136 0137 This allows you to transparently have nested Mappable values 0138 0139 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0140 data set 0141 0142 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to T 0143 0144 - returns: The value for the given key, if it can be converted to the expected type T 0145 */ 0146 @warn_unused_result 0147 public func from
Mapper.swift:191
        return try? self.from(field)
Mapper.swift:222
            if let value: T = try? self.from(field) {
<T: Mappable>(field: String) throws -> T { 0148 if let JSON = self.JSONFromField(field) as? NSDictionary { 0149 return try T(map: Mapper(JSON: JSON)) 0150 } 0151 0152 throw MapperError() 0153 } 0154 0155 /** 0156 Get an array of Mappable values from the given key in the source data 0157 0158 This allows you to transparently have nested arrays of Mappable values 0159 0160 Note: If any value in the array of NSDictionaries is invalid, this method throws 0161 0162 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0163 data set 0164 0165 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to [T] 0166 this mean Mapper throws if the given value is also not an array of NSDictionaries 0167 0168 - returns: The value for the given key, if it can be converted to the expected type [T] 0169 */ 0170 @warn_unused_result 0171 public func from
Mapper.swift:208
        return try? self.from(field)
<T: Mappable>(field: String) throws -> [T] { 0172 if let JSON = self.JSONFromField(field) as? [NSDictionary] { 0173 return try JSON.map { try T(map: Mapper(JSON: $0)) } 0174 } 0175 0176 throw MapperError() 0177 } 0178 0179 /** 0180 Get an optional Mappable value from the given key in the source data 0181 0182 This allows you to transparently have nested Mappable values 0183 0184 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0185 data set 0186 0187 - returns: The value for the given key, if it can be converted to the expected type T otherwise nil 0188 */ 0189 @warn_unused_result 0190 public func optionalFrom<T: Mappable>(field: String) -> T? { 0191 return try? self.from(field) 0192 } 0193 0194 /** 0195 Get an optional array of Mappable values from the given key in the source data 0196 0197 This allows you to transparently have nested arrays of Mappable values 0198 0199 Note: If any value in the provided array of NSDictionaries is invalid, this method returns nil 0200 0201 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0202 data set 0203 0204 - returns: The value for the given key, if it can be converted to the expected type [T] 0205 */ 0206 @warn_unused_result 0207 public func optionalFrom<T: Mappable>(field: String) -> [T]? { 0208 return try? self.from(field) 0209 } 0210 0211 /** 0212 Get an optional value from the given keys and source data. This returns the first non-nil value produced 0213 in order based on the array of fields 0214 0215 - parameter fields: The array of fields to check from the source data. 0216 0217 - returns: The first non-nil value to be produced from the array of fields, or nil if none exist 0218 */ 0219 @warn_unused_result 0220 public func optionalFrom<T: Mappable>(fields: [String]) -> T? { 0221 for field in fields { 0222 if let value: T = try? self.from(field) { 0223 return value 0224 } 0225 } 0226 0227 return nil 0228 } 0229 0230 // MARK: - T: Convertible 0231 0232 /** 0233 Get a Convertible value from a field in the source data 0234 0235 This transparently converts your types that conform to Convertible to properties on the Mappable type 0236 0237 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0238 data set 0239 0240 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to T 0241 0242 - returns: The value for the given key, if it can be converted to the expected type T 0243 */ 0244 @warn_unused_result 0245 public func from
Mapper.swift:311
            if let value: T = try? self.from(field) {
<T: Convertible where T == T.ConvertedType>(field: String) throws -> T { 0246 return try self.from(field, transformation: T.fromMap) 0247 } 0248 0249 /** 0250 Get an array of Convertible values from a field in the source data 0251 0252 This transparently converts your types that conform to Convertible to an array on the Mappable type 0253 0254 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0255 data set 0256 0257 - throws: `MapperError` if the value for the given key doesn't exist or cannot be converted to [T] 0258 0259 - returns: The value for the given key, if it can be converted to the expected type [T] 0260 */ 0261 @warn_unused_result 0262 public func from
Mapper.swift:297
        return try? self.from(field)
<T: Convertible where T == T.ConvertedType>(field: String) throws -> [T] { 0263 if let JSON = self.JSONFromField(field) as? [AnyObject] { 0264 return try JSON.map(T.fromMap) 0265 } 0266 0267 throw MapperError() 0268 } 0269 0270 /** 0271 Get a Convertible value from a field in the source data 0272 0273 This transparently converts your types that conform to Convertible to properties on the Mappable type 0274 0275 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0276 data set 0277 0278 - returns: The value for the given key, if it can be converted to the expected type T otherwise nil 0279 */ 0280 @warn_unused_result 0281 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> T? { 0282 return try? self.from(field, transformation: T.fromMap) 0283 } 0284 0285 /** 0286 Get an optional array of Convertible values from a field in the source data 0287 0288 This transparently converts your types that conform to Convertible to an array on the Mappable type 0289 0290 - parameter key: The key to retrieve from the source data, can be an empty string to return the entire 0291 data set 0292 0293 - returns: The value for the given key, if it can be converted to the expected type [T] 0294 */ 0295 @warn_unused_result 0296 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> [T]? { 0297 return try? self.from(field) 0298 } 0299 0300 /** 0301 Get an optional value from the given keys and source data. This returns the first non-nil value produced 0302 in order based on the array of fields 0303 0304 - parameter fields: The array of fields to check from the source data. 0305 0306 - returns: The first non-nil value to be produced from the array of fields, or nil if none exist 0307 */ 0308 @warn_unused_result 0309 public func optionalFrom<T: Convertible where T == T.ConvertedType>(fields: [String]) -> T? { 0310 for field in fields { 0311 if let value: T = try? self.from(field) { 0312 return value 0313 } 0314 } 0315 0316 return nil 0317 } 0318 0319 // MARK: - Custom Transformation 0320 0321 /** 0322 Get a typed value from the given key by using the given transformation 0323 0324 - parameter key: The key to retrieve from the source data, can be an empty string to return 0325 the entire data set 0326 - parameter transformation: The transformation function used to create the expected value 0327 0328 - throws: Any exception thrown by the transformation function, if you're implementing the transformation 0329 function you should use `MapperError`, see the documentation there for more info 0330 0331 - returns: The value of type T for the given key, if the transformation function doesn't throw 0332 */ 0333 @warn_unused_result 0334 public func from
Mapper.swift:246
        return try self.from(field, transformation: T.fromMap)
Mapper.swift:282
        return try? self.from(field, transformation: T.fromMap)
<T>(field: String, transformation: AnyObject? throws -> T) rethrows -> T { 0335 return try transformation(self.JSONFromField(field)) 0336 } 0337 0338 /** 0339 Get an optional typed value from the given key by using the given transformation 0340 0341 - parameter key: The key to retrieve from the source data, can be an empty string to return 0342 the entire data set 0343 - parameter transformation: The transformation function used to create the expected value 0344 0345 - returns: The value of type T for the given key, if the transformation function doesn't throw otherwise 0346 nil 0347 */ 0348 @warn_unused_result 0349 public func optionalFrom<T>(field: String, transformation: AnyObject? throws -> T?) -> T? { 0350 return (try? transformation(self.JSONFromField(field))).flatMap { $0 } 0351 } 0352 0353 // MARK: - Private 0354 0355 /** 0356 Get the AnyObject? for a given key. If an empty string is passed, return the entire data source. This 0357 allows users to create objects from multiple fields in the top level of the data source 0358 0359 - parameter field: The key to extract from the data source, can be an empty string to return the entire 0360 data source 0361 0362 - returns: The object for the given key 0363 */ 0364 private func JSONFromField
Mapper.swift:34
        if let value = self.JSONFromField(field) as? T {
Mapper.swift:89
        if let rawValue = self.JSONFromField(field) as? T.RawValue,
Mapper.swift:148
        if let JSON = self.JSONFromField(field) as? NSDictionary {
Mapper.swift:172
        if let JSON = self.JSONFromField(field) as? [NSDictionary] {
Mapper.swift:263
        if let JSON = self.JSONFromField(field) as? [AnyObject] {
Mapper.swift:335
        return try transformation(self.JSONFromField(field))
Mapper.swift:350
        return (try? transformation(self.JSONFromField(field))).flatMap { $0 }
(field: String) -> AnyObject? { 0365 return field.isEmpty ? self.JSON : self.JSON.valueForKeyPath(field) 0366 } 0367 } 0368