Slide 1

Slide 1 text

Develop with Swift

Slide 2

Slide 2 text

৿ాɹ௚थ

Slide 3

Slide 3 text

morizotter

Slide 4

Slide 4 text

2015

Slide 5

Slide 5 text

Github http://github.com/morizotter

Slide 6

Slide 6 text

Github Award https://github-awards.com/users/search?login=morizotter

Slide 7

Slide 7 text

TouchVisualizer https://github.com/morizotter/TouchVisualizer

Slide 8

Slide 8 text

SwiftyDrop https://github.com/morizotter/SwiftyDrop

Slide 9

Slide 9 text

Coggle https://coggle.it

Slide 10

Slide 10 text

Coggle https://coggle.it

Slide 11

Slide 11 text

Coggle https://coggle.it

Slide 12

Slide 12 text

Coggle https://coggle.it

Slide 13

Slide 13 text

angularjs-style-guide https://github.com/mgechev/angularjs-style-guide/blob/ master/README-ja-jp.md

Slide 14

Slide 14 text

angularjs-style-guide https://github.com/mgechev/angularjs-style-guide/blob/ master/README-ja-jp.md

Slide 15

Slide 15 text

Other contributions • SDWebImage • SwiftBond - Japanese 2 way binding • Evernote SDK • Treasuredata SDK • DateTools • Carthage • NVActivityIndicatorView • TagListView • FlatUIColors • …

Slide 16

Slide 16 text

Develop with Swift

Slide 17

Slide 17 text

Qolk Cozy Qiita Reader for iOS.

Slide 18

Slide 18 text

Qolk Cozy Qiita Reader for iOS.

Slide 19

Slide 19 text

Qolk QiitaΫϥΠΞϯτͷQolkΛMacbookͱCarthageͰ࡞ͬͨ࿩ http://qiita.com/morizotter/items/90d6d6024a6e7e0e9e84

Slide 20

Slide 20 text

Powerful Swift OSSs. • Dependency Manager: Carthage • Networking: Alamofire • JSON parser: SwiftyJSON • Database: Realm • Future(promise): BrightFutures • View binding: SwiftBond • Image loading: Kingfisher • AutoLayout: SnapKit

Slide 21

Slide 21 text

Powerful Swift OSSs. • Dependency Manager: Carthage Cocoapods • Networking: Alamofire AFNetworking • JSON parser: SwiftyJSON Mantle • Database: Realm MagicalRecord/CoreData • Future(promise): BrightFutures Bolts/PromiseKit • View binding: SwiftBond ReactiveCocoa? • Image loading: Kingfisher SDWebImage • AutoLayout: SnapKit Masonry Objective-C?

Slide 22

Slide 22 text

Core OSSs • Carthage • Alamofire • BrightFutures • SwiftyJSON

Slide 23

Slide 23 text

Carthage for all

Slide 24

Slide 24 text

Carthage • Decentralized • No .xcworkspace • Clean & Simple • Very Easy to distribute • Increasing • Centralized • .xcworkspace • Easy to use • Easy to distribute
 • Already many Cocoapods https://github.com/Carthage/Carthage https://cocoapods.org/

Slide 25

Slide 25 text

Carthage $ brew update $ brew install carthage $ cd move/to/app/root $ vi Cartfile github "Alamofire/Alamofire" == 3.1.2 wq $ carthage update -platform ios

Slide 26

Slide 26 text

Carthage

Slide 27

Slide 27 text

Carthage • Pros: • Project remains clean. • No build time. • Cons: • Library build time. • Relatively fewer libraries.

Slide 28

Slide 28 text

If library doesn’t compatible with Carthage?

Slide 29

Slide 29 text

Fork! Tweak! (Pull Request!)

Slide 30

Slide 30 text

Just 4 steps 1. Create CocoaTouch Framework 2. Add files to Framework target 3. Make scheme shared 4. git push and tag in Github

Slide 31

Slide 31 text

I made 5 libraries or more Carthage Compatible for Qolk.

Slide 32

Slide 32 text

Many Thanks.

Slide 33

Slide 33 text

Alamofire SwiftyJSON BrightFutures cooperate.

Slide 34

Slide 34 text

BrightFutures Networking system API Server App SwiftyJSON

Slide 35

Slide 35 text

Alamofire & BrightFutures // AlamofireClient.swift struct AlamofireClient { static let sharedInstance = AlamofireClient() let alamofire: Manager init() { let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForResource = RequestTimeoutSec alamofire = Manager(configuration: configuration) } static func requestJSON(URLRequest: URLRequestConvertible) -> Future { let promise = Promise() sharedInstance.alamofire.request(URLRequest) .validate() .responseJSON(options: .AllowFragments) { (response) -> Void in log.debug("REQUEST: \(response.request)") log.debug("RESPONSE: \(response.response)”) switch response.result { case .Success(let json): log.debug("[QIITA] JSON: \(json)") promise.success(JSONResponse(json: json, response: response.response!)) case .Failure(let error): log.debug("[QIITA] ERROR: \(error.localizedDescription)") self.errorHandling(error, response: response.response) promise.failure(ErrorResponse(nsError: error, response: response.response)) } } return promise.future } … } Return future.

Slide 36

Slide 36 text

Responses // AlamofireClient.swift struct JSONResponse { var json = JSON([]) var response: NSHTTPURLResponse? var rateLimit: Int? var rateRemaining: Int? init(json: AnyObject?, response: NSHTTPURLResponse?) { if let json = json { self.json = JSON(json) } if let response = response { self.response = response let headers = JSON(response.allHeaderFields) self.rateLimit = headers["Rate-Limit"].int self.rateRemaining = headers["Rate-Remaining"].int } } } struct ErrorResponse: ErrorType { var error: NSError var response: NSHTTPURLResponse? init(error: NSError, response: NSHTTPURLResponse? = nil) { self.nsError = error self.response = response } } Make original struct for easy handling.

Slide 37

Slide 37 text

BrightFutures & SwiftyJSON // AppManager.swift func getItems(pageInfo: PageInfo, query: String?) -> PageResponseFuture { let promise = Promise() AlamofireClient.requestJSON(QiitaAPIRouter.Items(pageInfo: pageInfo, query: query)) .onSuccess { (result: JSONResponse) in let pageResponse = PageResponse(json: result.json, pageInfo: pageInfo, response: result.response!) promise.success(pageResponse) } .onFailure { (errorResponse: ErrorResponse) in promise.failure(errorResponse) } return promise.future } struct PageResponse { var json: JSON var totalCount: Int? var pageInfo: PageInfo init(json: JSON, pageInfo: PageInfo, response: NSHTTPURLResponse?) { self.json = json self.pageInfo = pageInfo if let response = response { let headers = JSON(response.allHeaderFields) self.totalCount = headers["Total-Count"].intValue } } } typealias PageResponseFuture = Future Inject something before network returns.

Slide 38

Slide 38 text

SwiftyJSON final class Item: Object, ObjectCopyable { dynamic var renderedBody = "" dynamic var body = "" dynamic var coediting = false dynamic var createdAt = "" dynamic var itemId = "" dynamic var isPrivate = false let tags = List() dynamic var title = "" dynamic var updatedAt = "" dynamic var url = "" dynamic var user: User? override static func primaryKey() -> String? { return "itemId" } class func fromJSON(json: JSON) -> Item { let item = Item() item.renderedBody = json["rendered_body"].stringValue item.body = json["body"].stringValue item.coediting = json["coediting"].boolValue item.createdAt = json["created_at"].stringValue item.itemId = json["id"].stringValue item.isPrivate = json["private"].boolValue item.title = json["title"].stringValue item.updatedAt = json["updated_at"].stringValue item.url = json["url"].stringValue item.user = User.fromJSON(json["user"]) for (_, subJson): (String, JSON) in json["tags"] { item.tags.append(Tag.fromJSON(subJson)) } return item } … }

Slide 39

Slide 39 text

Sync Wantedly