swift事情2014夏 ~ swift入門 beta6対応

51
Swift 2014夏 デジタルサーカス(株)川智希

Upload: tomoki-hasegawa

Post on 28-May-2015

1.640 views

Category:

Software


1 download

DESCRIPTION

過去の勉強会で発表した「SwiftによるiOS開発再入門」「Objective-CプログラマのためのSwift導入法」を再構成して現時点で最新(beta6)仕様にアップデートしたものです。

TRANSCRIPT

  • 1. Swift 2014

2. CTO : iOS, Web : , (mbed), @tomzoh TOMZOH 3. iOS 4. WebPHP, CakePHP, Drupal iOS, Android) http://appbuilder.jp 2000 Samui 2001 Cebu 2002 Phuket 2004 Ishigaki 2005 Vietnam 2006 Hinn Do 2007 Bali 2008 Taiwan 2010 Seoul 2011 Macau 2012 Guam 2013 Phuket 5. 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 6. Playground Xcode6 Playground 7. 1. XcodeSwift 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 8. Product Name, Organization Name, Organization Identifier, Devies LanguageSwift 9. Master-Detail Application AppDelegate.swift Main.storyboard MasterViewController.swift DetailViewController.swift 10. Language 11. XcodeSwift Objecive-C 12. 2. Objective-CSwift 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 13. No .h, .m . Only .swift Interface BuilderIBOutlet, IBAction .swift Immutable / Mutable / / nil Dictionary, Array 14. Immutable / Mutable 15. / 16. Xcode Project, StoryBoard, Interface Builder Provisioning Profiles COCOAPODSObjective-C Cocoa Touch (Foundation Framework, UIKit, ) 17. 3. Objective-C Swift 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 18. Controller class definition // Super Class @interface MasterViewController : UITableViewController {} // Protocol(s) @interface LoveBeerListViewController : UIViewController {} Objective-C // Super Class class MasterViewController: UITableViewController {} // Protocol(s) class LoveBeerListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {} Swift : , 19. Super classs method Super classmethod override - (void)viewDidLoad {} - (void)viewWillAppear:(BOOL)animated {} - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{} override func viewDidLoad() {} override func viewWillAppear(animated: Bool){} override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {} Objective-C Swift 20. Protocol method Swift(: )( : ) UIKit Objective-C - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {} func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {} Objective-C Swift 21. IBOutlet .h.swift Interface Builder[Ctrl]+ ! @property (weak, nonatomic) IBOutlet UITableView *tableView; ! @IBOutlet var tableView: UITableView Objective-C Swift 22. IBAction IBOutlet Objective-CsenderUIButton or AnyObject - (IBAction)pushButton:(UIButton *)sender { } @IBAction func pushButton(sender: UIButton) { } Objective-C Swift 23. AnyObject and Type Casting LBShopTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ShopCell" forIndexPath:indexPath]; let cell: LBShopTableViewCell = tableView.dequeueReusableCellWithIdentifier("ShopCell", forIndexPath: indexPath) as LBShopTableViewCell Objective-C Swift dequeueReusableCellWithIdentifier:forIndexPath: Objective-CidSwiftAnyObject Swiftas [] 24. 4. Swift TIPS 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 25. SwiftTIPS Optional ARC Array / COCOAPODS SwiftyJSON ALAMOFIRE 26. 1. 2. COCOAPODS 3. 27. Optional 28. Optional Objective-C NSString nil Swift String nil nil Optional String Optional String String Optional 29. Optional nilOptional Optional 30. Optional - String ?Optional Chaining!Forced Unwrapping 31. Optional - if while Optional Binding let var OK unwrappedStr String optionalStr nil if false 32. Optional - Implicitly Unwrapped Optional Implicitly Unwrapped Optional nil 33. Optional - Optional String? Implicitly Unwrapped Optional String! ? ! 34. ARC 35. ARC SwiftARC strong, weak unowned 36. ARC // self self self.aProperty = { self.doSomething() } ! // unowned self self self.aProperty = { [unowned self] in self.doSomething() } 37. Array / 38. Array Swift Array Dictionary 39. 40. func for in key, value 41. COCOAPODS 1. 2. COCOAPODS 3. 42. COCOAPODS SwiftCOCOAPODS Podfile pod install -Bridging-Header.h Objective-CBridging Header // // Use this file to import your target's public headers that you would like to expose to Swift. // #import 43. COCOAPODS AFNetworking 44. 1. 2. COCOAPODS 3. 45. SwiftObjective-C AFNetworkingSDWebImageMBProgressHUD Objective-CObjective-C Swift 46. SwiftyJSON JSONSwift ! shopName = (((json as? NSArray)?[0] as? NSDictionary)?["shop"] as? NSDictionary)?["name"] shopName = json[0]["shop"]["name"].string 47. ALAMOFIRE Alamofire is an HTTP networking library written in Swift. Think of it as AFNetworking, reimagined for the conventions of this new language. ! ! ! Xcode beta6 Alamofire.request(.GET, "https://qiita.com/api/v1/tags.json").response { (request, response, data, error) in let json: [JSONValue] = JSONValue(data!).array for tag in tags { println(tag["name"].string) } } 48. 5. 1. XcodeSwift 2. Objective-CSwift 3. Objective-CSwift 4. Swift TIPS 5. 49. Kindle Swift iBooks Swift The Swift Programming Language ! Qiita Swift 50. @tomzoh