0001 /** 0002 The Convertible protocol defines how to convert values to custom objects 0003 this differs from the Mappable protocol because the creation function is passed 0004 an AnyObject, allowing your definition to accept any data, and convert it as seen fit 0005 0006 NSURL's Convertible implementation is provided by default, assuming the passed value 0007 is a String 0008 0009 Example: 0010 0011 // Convertible implementation for custom logic to create `CLLocationCoordinate2D`s from dictionaries 0012 extension CLLocationCoordinate2D: Convertible { 0013 public static func fromMap(value: AnyObject?) throws -> CLLocationCoordinate2D { 0014 guard let location = value as? NSDictionary, 0015 let latitude = (location["lat"] ?? location["latitude"]) as? Double, 0016 let longitude = (location["lng"] ?? location["longitude"]) as? Double else 0017 { 0018 throw MapperError() 0019 } 0020 0021 return CLLocationCoordinate2D(latitude: latitude, longitude: longitude) 0022 } 0023 } 0024 */ 0025 public protocol Convertible{ 0026 /// This typealias allows us to enforce the returned value is of type Self, without requiring 0027 /// implementations to return a value using `self.init` 0028 typealias ConvertedType
Mapper.swift:245 public func from<T: Convertible where T == T.ConvertedType>(field: String) throws -> T {Mapper.swift:262 public func from<T: Convertible where T == T.ConvertedType>(field: String) throws -> [T] {Mapper.swift:281 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> T? {Mapper.swift:296 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> [T]? {Mapper.swift:309 public func optionalFrom<T: Convertible where T == T.ConvertedType>(fields: [String]) -> T? {NSURL+Convertible.swift:9 extension NSURL: Convertible {= Self 0029 0030 /** 0031 `fromMap` returns the expected value based off the provided input, this allows you to attempt 0032 to cast the value to anything you'd like, and perform any manipulation on it (don't use this as a 0033 conversion mechanism, instead see Transform) 0034 0035 - parameter value: Any value (probably from the data source's value for the given key) to create 0036 the expected object with 0037 0038 - throws: Any error from your custom implementation, `MapperError` is recommended 0039 0040 - returns: The successfully created value from the given input 0041 */ 0042 @warn_unused_result 0043 static func fromMap
Convertible.swift:43 static func fromMap(value: AnyObject?) throws -> ConvertedTypeMapper.swift:245 public func from<T: Convertible where T == T.ConvertedType>(field: String) throws -> T {Mapper.swift:262 public func from<T: Convertible where T == T.ConvertedType>(field: String) throws -> [T] {Mapper.swift:281 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> T? {Mapper.swift:296 public func optionalFrom<T: Convertible where T == T.ConvertedType>(field: String) -> [T]? {Mapper.swift:309 public func optionalFrom<T: Convertible where T == T.ConvertedType>(fields: [String]) -> T? {(value: AnyObject?) throws -> ConvertedType 0044 } 0045
Mapper.swift:246 return try self.from(field, transformation: T.fromMap)Mapper.swift:264 return try JSON.map(T.fromMap)Mapper.swift:282 return try? self.from(field, transformation: T.fromMap)