swift library

Download Swift Library

Post on 08-Aug-2015

29 views

Category:

Software

3 download

Embed Size (px)

TRANSCRIPT

  1. 1. Swi$%
  2. 2. Swi$% 2014/06(:(Swi-((WWDC(2014) 2014/09(:(Swi-(1.0((Xcode(6.0) 2014/10(:(Swi-(1.1((Xcode(6.1) 2015/04(:(Swi-(1.2((Xcode(6.3) 2015/06(:(Swi-(?.?((WWDC(2015(?)
  3. 3. Swi$% Modern Designed,for,Safety
  4. 4. Modern StructEnum
  5. 5. Designed(for(Safety var let Array/Dic.onary1 Op.onalnil1
  6. 6. Swi$%
  7. 7. Objec&ve(C* Bridging(Header CocoaPods( Swi3( (Op6onal(
  8. 8. Swi$% "Swi&" Objec,ve.C""Swi&" Swi&"
  9. 9. Alamore
  10. 10. Alamore AFNetworking..Swi0. Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"]) .response { (request, response, data, error) in println(response) println(error) }
  11. 11. APIKit
  12. 12. APIKit Swi%& let request = GitHub.SearchRepositories(query: "APIKit", sort: .Stars) GitHub.sendRequest(request) { response in switch response { case .Success(let box): // SearchRepositories println(box.value) case .Failure(let box): // NSError println(box.value) } }
  13. 13. Result
  14. 14. Result "APIKit" enum Result { case Success(Box) case Failure(Box) } result = someFunc() // Result switch result { case .Success(let box): // box.value: String case .Failure(let box): // box.value: NSError }
  15. 15. Op#onal( Op$onal/ enum Optional { case Some(T) case None } Result((nil((None)( Haskell(Op4onal((Maybe(Result(( Either(
  16. 16. Swi$yJSON
  17. 17. Swi$yJSON let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) if let statusesArray = JSONObject as? [AnyObject], let status = statusesArray[0] as? [String: AnyObject], let user = status["user"] as? [String: AnyObject], let userName = user["name"] as? String { // userName } let json = JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string { // userName }
  18. 18. ObjectMapper
  19. 19. ObjectMapper Mantle((Swi,( struct Temperature: Mappable { var celcius: Double? var fahrenheit: Double? init(){} init?(_ map: Map) { mapping(map) } mutating func mapping(map: Map) { celcius