Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenmaz/ad35afcb2a37f3cd0d9060a54186ae00 to your computer and use it in GitHub Desktop.
Save kenmaz/ad35afcb2a37f3cd0d9060a54186ae00 to your computer and use it in GitHub Desktop.
# まとめblog
http://niwatako.hatenablog.jp/entry/2016/03/05/022452
===================================================================
# Swiftのエコシステムに飛び込む #tryswiftconf Day1-1
http://niwatako.hatenablog.jp/entry/2016/03/02/105937
★聞いてない奴
OSSになっていろいろ動きが
## server side swift
IBM bluemix
https://swiftlang.ng.bluemix.net/#/repl
IBM Kitura
https://github.com/IBM-Swift/Kitura
サーバーサイドswift framework
## online document
cocoapods配下のコードのdocs生成(appledoc or jazzy)
swiftだけじゃないけど
http://cocoadocs.org/docsets/KMZDrawView/0.0.1/
ところでjazzy
https://github.com/realm/jazzy
Clang/SourceKitをフックしてASTを作ってrubyでサイト生成しているらしい
## カバレッジ
codecov
https://codecov.io/github/kenmaz
githubと連携してカバレッジとってレポートしてくれるサービス
HoundCI
based on SwiftLint
githubと連携してSwiftLintしてくれるサービス
例)
https://github.com/kenmaz/KMZDrawView/pull/2
#swift related dev tools
## パッケージ管理
Carthage
CococaPods
SwiftPackageManager
Swift3で正式版
## swift and xcode
SourceKit
=> >SourceKitten : SourceKitのラッパー的なもの
=> SwiftLint
=> jazzy
=> SourceKittenDaemon: いろんなtexteidtorでswiftコード補完サポートするデーモン
atomとかで使えるサンプルあるらしい
## リソース生成
SwiftGen
swiftコード生成ツールまとめたやつ
https://github.com/AliSoftware/SwiftGen
enums for your Assets Catalogs
enums for your Localizable.strings strings.
enums for your UIStoryboard and their Scenes
enums for your UIColors.
R.Swift
同じくコード生成ツール
https://github.com/mac-cain13/R.swift
Images
Custom fonts
Resource files
Colors
Storyboards
Segues
Nibs
Reusable cells
clg
https://github.com/griffin-stewie/clg
jsonとかcsv => clr => swiftとかのコード生成
adobeのカラーテーマ(ASE)とかをswiftコードに変換
ASE: Adobe Swatch Exchange file
https://milligramme.github.io/2009/08/26/indesign-adobe_swatch_exchange-ase.html
# TEST
Quick, Spectre
BDD framework
# まとめ
実際に使って、PR投げたりして貢献しよう
# QA
swift package manager => 将来的にxcode統合されるらしいけど、しばらくはcarthage/podどっちも使われる
carthageの発音 => カルタゴ、カーセージ、ネイティブでも発音割れてるらしいので、どっちでもOK
===================================================================
# 実践的クロスプラットフォームSwift
http://niwatako.hatenablog.jp/entry/2016/03/02/105742
クロスプラットフォームでswift開発するときのtips
いまいちピンときてない
linux dockerでmac上に環境作るのがオススメ
https://github.com/swiftdocker/docker-swift
http://qiita.com/taketin/items/77af9bc29f44166b8270
SPM
コードを複数のpackage(project)に分けて書くのがオススメ
依存性
objc runtimeに依存
gcdに依存
Darwinに依存
`#if os(Linux)`
的なコード沢山書くことになる
Testing
SPMでpackageを作るとTestターゲット作ってくれるようになったよ
CI
TravisCI楽でいいよ
========================================================================
コードリーディングについて
http://niwatako.hatenablog.jp/entry/2016/03/02/115920
読み手のことを考えてコードを書こう
流暢なコードがいいとは限らない
10回くらい見ないと規則性が見えないコードX
解読 != 読み取れる
読めることが重要
スラングつかわない
パターンを使う
========================================================================
AppleTV
http://niwatako.hatenablog.jp/entry/2016/03/02/122740
skip
========================================================================
平常心で型を消し去る
http://niwatako.hatenablog.jp/entry/2016/03/02/125706
具象型と抽象型
具象型
class SomeClass {}
let obj:SomeClass
これはOK
抽象型
class GenericClass<T> {}
let obj:GenericClass<T>
これはNG
swiftはTが何なのかわかってないから
プレースホルダ型に具象型を埋めればOK
class GenericClass<T> {}
let obj:GenericClass<String>
ただしprotocolではこれが不可能
=> ポケモンの例をplaygroundで
https://gist.github.com/kenmaz/b618fbc0d9d8b6f32836d5d58e0e36ac
実例:
https://github.com/Carthage/Commandant/blob/0.8.3/Sources/Commandant/Command.swift#L32-L66
GenericなprotocolであるCommandはなんでも入れられる型 CommandWrapper
Javaなら書ける
http://brightechno.com/blog/archives/391
----
これはSwiftの言語仕様の問題です。SwiftのprotocolはJavaのinterfaceと違い、クラス実装時の制約であり型ではないためです。
-----
========================================================================
プロトコルと約束の地
http://niwatako.hatenablog.jp/entry/2016/03/02/152738
protocol, generics, objcとのmix, いろいろ限界がある
## as? lies
let vender = ObjcObject()
let items = vendor.giveMeItems() as? [Fruit] //NG(?)
let items = vendor.giveMeItems().map { $0 as Fruit} //OK(?)
Objective-C側からSwiftにブリッジする時機能しないのです。
=> これはウソのような? 手元では再現できず
## header
- MyApp-Swifth.hはheaderに#importできない
## プロトコルコンポジション
objcのUIViewController<Themalable>的なことができない
プロトコルコンポジション使う
protocol A
protocol B
protocol AB: A, B
UIViewController != protocol
解1) UIViewControllerProtocol
UIViewControllerにあわせてprotocolを自作 => つらい
解2) computed propertyを使う
結局はas!
# Protocol + Generics のつらみ
## Covariance
protocol Holder {
typealias Item
}
var hoge:Holder //NG
swiftのprotocol+generic は Covariance(共分散) に対応していない(@see also: 型消去)
## nest
ネストしたクラスにgenericしていできない(トップレベルだけ)
========================================================================
文化を調和させる
http://niwatako.hatenablog.jp/entry/2016/03/02/160011
sample code
http://qiita.com/masashi-sutou/items/7d2953d86397123e84e6
資料
https://speakerdeck.com/masashi_sutou/wen-hua-wodiao-he-saseru-woyatutemiru-try-blending-culture
suit=スート=トランプのマーク
## first_demo
-apple MVC
-VCとModelが密結合
-ビジネスロジックはある程度Modelに
-cellのsetupもVC
# second_demo
-Handをstruct、immutableに => POP
-Hand#moveCard => FP
-CellをCustomCellに => MVVM(?)
たぶんCustomCell(CustomCell)クラスがViewModelという扱い?
# third_demo
-HandをDataType protocolに引き上げ
DataType = insert/delete/move可能なコレクション
その実装 = Hand
-DataSourceをVCから分離 => VC-Model依存を除去
DataSourceは Hand ではなく DataType をpropertyにもつ
-DataSourceから UITableViewDataSource 実装と、それ以外を分離 => SourceType:UITableViewDataSource
-SourceType protocol extensionでinsert/delete実装
# forth_demo
-DataSource#addItemTo を SourceTypeに引き上げ、条件判定をconditionForAddingプロトコルメソッドに切り出し
テンプレートメソッドパターン
=>OOP的
-DataSourceのサブクラスHandDataSourceを作成、こちらにHandを依存、DataSourceからHand依存を除去
DataSource#conditionForAddingのデフォルト実装がださい
最終的に
-HandDataStore, CardCell のみが Model(Hand/Card)に依存
-OOP/POP/FPが調和
========================================================================
HomeKitの話
http://niwatako.hatenablog.jp/entry/2016/03/02/173530
========================================================================
http://niwatako.hatenablog.jp/entry/2016/03/02/180745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment