NSError? let jsonObject: AnyObject! = NSJSONSerialization.JSONObjectWithData(...) if let err = jsonError { return nil } if let statuses = jsonObject as? Array<AnyObject> { if let aStatus = statuses[0] as? Dictionary<String, AnyObject> { if let user = aStatus["user"] as? Dictionary<String, AnyObject> { if let username = user["name"] { //Finally We Get The Username return username } } } } // if all else fails return nil return nil } Amit Bijlani, @paradoxed - 2015
Array<AnyObject> { if let aStatus = statuses[0] as? Dictionary<String, AnyObject> { if let user = aStatus["user"] as? Dictionary<String, AnyObject> { if let username = user["name"] { //Finally We Get The Username return username } } } } Amit Bijlani, @paradoxed - 2015
parseData(data, {(result: Result<String>) -> () in switch result { case let .Error(err): println("Error") case let .Value(userName): println(userName.value) } }) Amit Bijlani, @paradoxed - 2015
// Trailing closure parseData(data) {result in switch result { case let .Error(err): println("Something went wrong!") case let .Value(userName): println(userName.value.name) } } Amit Bijlani, @paradoxed - 2015
takes, it will return a function that takes the remaining parameters" struct User { let name: String let profileDescription: String let followersCount: Int static func create(name: String)(profileDescription: String)(followersCount: Int) -> User { return User(name: name, profileDescription: profileDescription, followersCount: followersCount) } } Amit Bijlani, @paradoxed - 2015