[String: String]? = nil) -> NSURLRequest { var request = NSMutableURLRequest(…) To be or not to be: optional if headers != nil { for (key,val) in headers! { request.addValue(val, forHTTPHeaderField: key) } } let paramSeparator = request.URL?.query != nil ? "&" : "?" if let headers = headers { for (key,val) in headers { request.addValue(val, forHTTPHeaderField: key) } } aerogear-ios-http
*/ public class TrustedPersistantOAuth2Session: OAuth2Session { private let keychain: KeychainWrap /** The access token. The information is read securely from Keychain. */ public var accessToken: String? { get { return self.keychain.read(self.accountId, tokenType: .AccessToken) } set(value) { if let unwrappedValue = value { let result = self.keychain.save(self.accountId, tokenType: .AccessToken, value: unwrappedValue) } } } Computed properties aerogear-ios-oauth2
"john", "lastname": "doe", "address": { "street": "Buch Street", "poBox": 123, "city": "Glasgow", "country": "UK" } } class Person { var firstname: String? var lastname: String var address: Address? } class Address { var street: String var poBox: Int var city: String var country: String } class Person: JSONSerializable { var firstname: String? var lastname: String var address: Address? required init() {} class func map(source: JsonSZ, object: Person) { object.firstname <= source["firstname"] object.lastname <= source["lastname"] object.address <= source["address"] } } aerogear-ios-jsonsz // serialize from json var serializer = JsonSZ() let developer:Person = serializer.fromJSON(developerJSON, to: Person.self) XCTAssertTrue(developer.firstname == "john") XCTAssertTrue(developer.lastname == "doe")
JsonSZ) { if let value = right.value { field = value as? String } } aerogear-ios-jsonsz public func <=(inout left: Int?, right: JsonSZ) { if let value = right.value { field = value as? Int } } public func <=(inout left: Bool?, right: JsonSZ) { if let value = right.value { field = value as? Bool } }
JsonSZ) { if let value: AnyObject = right.value { switch T.self { case is String.Type, is Bool.Type, is Int.Type, is Double.Type, is Float.Type: field = value as? T . . . default: field = nil return } } } public func <=<T: JSONSerializable>(inout left: T?, right: JsonSZ) { if let value = right.value as? [String: AnyObject] { field = JsonSZ().fromJSON(value, to: T.self) } } aerogear-ios-jsonsz