Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Develop with Swift
Search
Morita Naoki
November 27, 2015
Technology
3
1.3k
Develop with Swift
Swift development environment is already prepared.
Morita Naoki
November 27, 2015
Tweet
Share
More Decks by Morita Naoki
See All by Morita Naoki
TouchVisualizer Demo movie #potatotips
morizotter
1
5k
KPTをやってみた
morizotter
4
21k
Other Decks in Technology
See All in Technology
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
410
Deno+JSRでパッケージを作って公開する
askua
0
120
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
380
Can We Measure Developer Productivity?
ewolff
1
110
Engineering at LY Corporation
lycorp_recruit_jp
0
570
The Role of Developer Relations in AI Product Success.
giftojabu1
0
110
形式手法の 10 メートル手前 #kernelvm / Kernel VM Study Hokuriku Part 7
ytaka23
5
820
利きプロセススケジューラ
sat
PRO
5
2.7k
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
1
140
スクラムチームを立ち上げる〜チーム開発で得られたもの・得られなかったもの〜
ohnoeight
2
330
QAEチームが辿った3年 ボクらが改善業務にスクラムを選んだワケ / 20241108_cloudsign_ques23
bengo4com
0
1.3k
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
450
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Thoughts on Productivity
jonyablonski
67
4.3k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9k
It's Worth the Effort
3n
183
27k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
For a Future-Friendly Web
brad_frost
175
9.4k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
400
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
4 Signs Your Business is Dying
shpigford
180
21k
Faster Mobile Websites
deanohume
305
30k
YesSQL, Process and Tooling at Scale
rocio
168
14k
Transcript
Develop with Swift
ాɹथ
morizotter
2015
Github http://github.com/morizotter
Github Award https://github-awards.com/users/search?login=morizotter
TouchVisualizer https://github.com/morizotter/TouchVisualizer
SwiftyDrop https://github.com/morizotter/SwiftyDrop
Coggle https://coggle.it
Coggle https://coggle.it
Coggle https://coggle.it
Coggle https://coggle.it
angularjs-style-guide https://github.com/mgechev/angularjs-style-guide/blob/ master/README-ja-jp.md
angularjs-style-guide https://github.com/mgechev/angularjs-style-guide/blob/ master/README-ja-jp.md
Other contributions • SDWebImage • SwiftBond - Japanese 2 way
binding • Evernote SDK • Treasuredata SDK • DateTools • Carthage • NVActivityIndicatorView • TagListView • FlatUIColors • …
Develop with Swift
Qolk Cozy Qiita Reader for iOS.
Qolk Cozy Qiita Reader for iOS.
Qolk QiitaΫϥΠΞϯτͷQolkΛMacbookͱCarthageͰ࡞ͬͨ http://qiita.com/morizotter/items/90d6d6024a6e7e0e9e84
Powerful Swift OSSs. • Dependency Manager: Carthage • Networking: Alamofire
• JSON parser: SwiftyJSON • Database: Realm • Future(promise): BrightFutures • View binding: SwiftBond • Image loading: Kingfisher • AutoLayout: SnapKit
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?
Core OSSs • Carthage • Alamofire • BrightFutures • SwiftyJSON
Carthage for all
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/
Carthage $ brew update $ brew install carthage $ cd
move/to/app/root $ vi Cartfile github "Alamofire/Alamofire" == 3.1.2 wq $ carthage update -platform ios
Carthage
Carthage • Pros: • Project remains clean. • No build
time. • Cons: • Library build time. • Relatively fewer libraries.
If library doesn’t compatible with Carthage?
Fork! Tweak! (Pull Request!)
Just 4 steps 1. Create CocoaTouch Framework 2. Add files
to Framework target 3. Make scheme shared 4. git push and tag in Github
I made 5 libraries or more Carthage Compatible for Qolk.
Many Thanks.
Alamofire SwiftyJSON BrightFutures cooperate.
BrightFutures Networking system API Server App SwiftyJSON
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<JSONResponse, ErrorResponse> { let promise = Promise<JSONResponse, ErrorResponse>() 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.
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.
BrightFutures & SwiftyJSON // AppManager.swift func getItems(pageInfo: PageInfo, query: String?)
-> PageResponseFuture { let promise = Promise<PageResponse, ErrorResponse>() 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<PageResponse, ErrorResponse> Inject something before network returns.
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<Tag>() 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 } … }
Sync Wantedly