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
Making Your App Static
Search
Yusei Nishiyama
July 14, 2015
Technology
13
4.2k
Making Your App Static
Making Your App Static with Swift
Yusei Nishiyama
July 14, 2015
Tweet
Share
More Decks by Yusei Nishiyama
See All by Yusei Nishiyama
Continuous Mobile App Delivery
yuseinishiyama
0
740
Working at Cookpad UK
yuseinishiyama
2
3.5k
Building iOS apps at scale (Mobilization)
yuseinishiyama
4
1.8k
Working at Scale
yuseinishiyama
3
820
Building iOS apps at scale
yuseinishiyama
2
1.3k
Reduce Build Times and Get Home Eariler
yuseinishiyama
2
770
How to make your app international
yuseinishiyama
3
7.5k
Safer Networking Layer With Swift
yuseinishiyama
0
280
え!? Swift使ってるのにそんな書きかたしてるのですか!?
yuseinishiyama
28
9.1k
Other Decks in Technology
See All in Technology
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
SSMRunbook作成の勘所_20241120
koichiotomo
1
110
Terraform Stacks入門 #HashiTalks
msato
0
350
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
570
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Platform Engineering for Software Developers and Architects
syntasso
1
510
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
120
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
210
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
2
220
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Statistics for Hackers
jakevdp
796
220k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
A Philosophy of Restraint
colly
203
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
BBQ
matthewcrist
85
9.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
How to Ace a Technical Interview
jacobian
276
23k
Music & Morning Musume
bryan
46
6.2k
Transcript
.BLJOH:PVS "QQ4UBUJD :VTFJ/JTIJZBNB !ZVTFJOJTIJZBNB QPUBUPUJQT
8IPBN* w :VTFJ/JTIJZBNB !ZVTFJOJTIJZBNB w J04EFWFMPQFS ZFBST w $PPLQBE
w *OUFSOBUJPOBMHSPVQ w -FBSOJOH&OHMJTI
(MPCBM
/PXXFIBWFB TUBUJDMBOHVBHFʜ
5IFSFTUJMM SFNBJOTBMPUPG EZOBNJDQBSU
6*7JFX$POUSPMMFS
let storyBoard = UIStoryboard(name: "Main", bundle: nil) let vc =
storyBoard.instantiateViewControllerWithIdentifier("FooBar") as! FooBarViewController navigationController?.pushViewController(vc, animated: true) class FooBarViewController : UIViewController {}
$PEF(FOFSBUPS wLS[Z[BOPXTLJN/BUBMJF wTRVBSFPCKDDPEFHFOVUJMT wQBVMTBNVFMT4#$POTUBOUT
4UPSZCPBSE 7JFX$POUSPMMFS w $MBTTOBNF'JMFOBNF 4UPSZCPBSE ‣ 'PP#BS7JFX$POUSPMMFSTXJGU ‣ 'PP#BS7JFX$POUSPMMFSTUPSZCPBSE
w 4UPSZCPBSE&OUSZ1PJOU class FooBarViewController : UIViewController { var aProperty: Int?
protocol StoryboardInstantiable {} func instantiate<T: StoryboardInstantiable>(_: T.Type) -> T {
let storyBoard = UIStoryboard(name: TypeNameFromType(T), bundle: nil) return storyBoard.instantiateInitialViewController() as! T } extension FooBarViewController : StoryboardInstantiable {} let vc = instantiate(FooBarViewController) vc.aProperty = 1 navigationController?.pushViewController(vc, animated: true) 1SPUPDPM (MPCBM'VODUJPO
1SPUPDPM&YUFOTJPO protocol StoryboardInstantiable {} extension StoryboardInstantiable { static func instantiate()
-> Self { let storyBoard = UIStoryboard(name: TypeNameFromType(Self), bundle: nil) return storyBoard.instantiateInitialViewController() as! Self } } extension FooBarViewController : StoryboardInstantiable {} let vc = FooBarViewController.instantiate() vc.aProperty = 1 4XJGU
5ZQF$POTUSBJOUT extension StoryboardInstantiable where Self: UIViewController { static func instantiate()
-> Self { let storyBoard = UIStoryboard(name: TypeNameFromType(Self), bundle: nil) return storyBoard.instantiateInitialViewController() as! Self } } class SomeClass : StoryboardInstantiable {} SomeClass.instantiate() // Compile error
)PXUPHFU BUZQFOBNF
0CKFDUJWF$ NSString * className = NSStringFromClass([FooBarViewController class]); NSLog(@"Class name is
%@", className);
4XJGU let classString = NSStringFromClass(FooBarViewController) // => Potatotips.FooBarViewController classString.componentsSeparatedByString(".").last! //
=> FooBarViewController
/FTUFE$MBTT class Hoge { class FooBarViewController : UIViewController {} }
println(Hoge.FooBarViewController.self) // => Potatotips.Hoge.FooBarViewController println(NSStringFromClass(Hoge.FooBarViewController.self)) // => _TtCC10Potatotips4Hoge20FooBarViewController println(Hoge.FooBarViewController.self.description()) // => _TtCC10Potatotips4Hoge20FooBarViewController println(Hoge.FooBarViewController.self.debugDescription()) // => _TtCC10Potatotips4Hoge20FooBarViewController
None
.BOHMFE/BNF $ xcrun swift-demangle _TtCC10Potatotips4Hoge20FooBarViewController _TtCC10Potatotips4Hoge20FooBarViewController ---> Potatotips.Hoge.FooBarViewController _T t
CC 10Potatotips 4Hoge 20FoobarViewController Swift global symbol Type 2 nested class Module name (10 characters) Class name Class name
%FNBOHMFE5ZQF/BNF println(reflect(Hoge.FooBarViewController.self).summary) // => Potatotips.Hoge.FooBarViewController println(toString(Hoge.FooBarViewController.self)) // => Potatotips.Hoge.FooBarViewController
TUSVDUPSFOVN struct A { struct B { struct C {}
} } enum X { enum Y {} } println(reflect(A.B.C.self).summary) // => Potatotips.A.B.C println(reflect(X.Y.self).summary) // => Potatotips.X.Y println(toString(A.B.C.self)) // => Potatotips.A.B.C println(toString(X.Y.self)) // => Potatotips.X.Y
4XJGU print(String(Hoge.FooBarViewController.self)) // => Potatotips.Hoge.FooBarViewController
6*5BCMF7JFX
override func tableView( tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{ let cell = tableView.dequeueReusableCellWithIdentifier( "Cell", forIndexPath: indexPath) as! FooBarCell /4*OEFY1BUI
NSIndexPath Meaning
enum Section { case Birds(row: Bird), Fishes(row: Fish) enum Bird:
Int { case Parrot, Owl, Woodpeckers } enum Fish: Int { case Carp, Dragonfish } init?(indexPath: NSIndexPath) { switch (indexPath.section, indexPath.row) { case (0, let x): guard let bird = Bird(rawValue: x) else { return nil } self = Birds(row: bird) case (1, let x): guard let fish = Fish(rawValue: x) else { return nil } self = Fishes(row: fish) default: return nil } } var indexPath: NSIndexPath { switch self { case .Birds(let row): return NSIndexPath(forRow: row.rawValue, inSection: 0) case .Fishes(let row): return NSIndexPath(forRow: row.rawValue, inSection: 1) } } }
override func tableView( tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{ let title: String if let section = Section(indexPath: indexPath) { switch section { case .Birds(row: .Owl): title = "Owl" default: title = "Other" } } else { title = "Invalid" } // ...
6*5BCMF7JFX$FMM override func tableView( tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier( "Cell", forIndexPath: indexPath) as! FooBarCell
$MBTTOBNF 'JMFOBNF OJC *EFOUJpFS
extension UITableView { func registerNibForCellWithType<T: UITableViewCell>(type: T.Type) { let className
= TypeNameFromType(T) let nib = UINib(nibName: className, bundle: nil) registerNib(nib, forCellReuseIdentifier: className) } func registerClassForCellWithType<T: UITableViewCell>(type: T.Type) { let className = TypeNameFromType(T) registerClass(T.self, forCellReuseIdentifier: className) } func dequeueReusableCellWithType<T: UITableViewCell>( type: T.Type, forIndexPath indexPath: NSIndexPath) -> T { return dequeueReusableCellWithIdentifier( TypeNameFromType(T), forIndexPath: indexPath) as! T } } 3FHJTUFSBOE %FRVFVFCZ5ZQF
class FooBarCell : UITableViewCell { @IBOutlet weak var label: UILabel!
} // Register let tableView = UITableView() tableView.registerNibForCellWithType(FooBarCell) // Dequeue let cell = tableView.dequeueReusableCellWithType( FooBarCell.self, forIndexPath: indexPath) cell.label.text = title 1VUUIFNJOUP "DUJPO
4VNNBSZ
w'JOETPNFUIJOHXSPOHPO lDPNQJMFUJNFz w(FOFSBUJOHTUSJOHTGSPN UZQFT w3FEVDFDPEFXJUIHFOFSJDT
8FBSFIJSJOH
"OZ2VFTUJPOT