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
Objective-C Programming Guide for Open Source S...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yosuke Ishikawa
February 01, 2014
Technology
9.5k
31
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Objective-C Programming Guide for Open Source Software
2014/02/01 @ GREE
Yosuke Ishikawa
February 01, 2014
More Decks by Yosuke Ishikawa
See All by Yosuke Ishikawa
効率的な開発手段として VRTを活用する
ishkawa
1
250
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
4.6k
Achieving Testability in Presentation Layer
ishkawa
4
4k
Introducing Wire: Dependency Injection by Code Generator
ishkawa
12
1.4k
Declarative UICollectionView
ishkawa
28
8.5k
Nuxt.jsが掲げる"Universal Vue.js Applications"とは何者か
ishkawa
10
2.9k
Static Dependency Injection by Code Generation
ishkawa
15
6.8k
実践クライアントサイドSwift
ishkawa
23
4.4k
JSON-RPC on APIKit
ishkawa
5
69k
Other Decks in Technology
See All in Technology
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
160
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
0
2k
Docker Desktop不要の時代が来る? WSL標準の「wslc」で Linuxコンテナを動かしてみた.
ueponx
0
730
ループエンジニアリングでE2Eテストを実践
noriyukitakei
0
290
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
250
依頼文化をやめる日 EM視点で語るPlatform EngineeringとInclusive SRE / Discussing Platform Engineering and Inclusive SRE from an EM's Perspective
shin1988
3
2.6k
Keeping applications secure by evolving OAuth 2.0 and OpenID Connect
ahus1
PRO
1
150
Terraform共通モジュールをチーム横断で“変えられる”運用へ ― リリースと適用の分離
kekke_n
0
440
AI Driven AI Governance
pict3
0
130
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
140
なぜ私たちのSREプラクティスはなかなか機能しないのか 〜システムより先に組織を見る〜 / Why our SRE practices aren't really working
vtryo
0
1.1k
オブザーバビリティ、本当に活用できてる? 〜API連携×生成AIで成熟度を自動評価〜
dmmsre
0
710
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
320
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
310
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
180
The Curious Case for Waylosing
cassininazir
1
420
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Optimizing for Happiness
mojombo
378
71k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
500
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
340
Transcript
ެ։༻ͷObjective-Cͷॻ͖ํ @_ishkawa
ࣗݾհ
None
GHFeed
IS ISDiskCache ISMemoryCache ISHTTPOperation ISRemoveNull ISPersistentStack ISMethodSwizzling ISBackGesture ISRefreshControl ISColumnsController
ISRevealController ISCyclicPagesView ISFakeInterfaceOrientation ISInteractiveEdgesNavigationBar ISAlternativeRefreshControl
None
8 Pods 551 Stars
τʔΫ֓ཁ
“ެ։༻” | | ଞਓ͏ίʔυ
͔ࣗ͠৮Δ͜ͱͷͳ͍ΞϓϦͷ ίʔυ͖ͳΑ͏ʹॻ͚͍͍ (ࣗݾͰ)
͔͠͠ɺଞਓ৮ΔՄೳੑ͕͋Δ߹
✓ ୭Ͱ؆୯ʹಋೖͰ͖Δ ✓ ୭Ͱਖ਼͘͠ѻ͏͜ͱ͕Ͱ͖Δ ✓ ଞͷίʔυͷ෭࡞༻͕ͳ͍ ✓ γϯϘϧϦιʔε͕িಥ͠ͳ͍ ͱ͍ͬͨ͜ͱ͕ٻΊΒΕΔͷͰɺࠓͦͷΛ͠·͢ɻ
1.ΞϓϦͱͷিಥ 2.ྑ͍@interface 3.Ϣχοτςετ τʔΫ֓ཁ
1.ΞϓϦͱͷিಥ
2छྨͷিಥ ✗ γϯϘϧͷিಥ ✗ Ϧιʔεͷিಥ
1.1.γϯϘϧͷিಥ
✗ Ϋϥεͷিಥ ✗ ΧςΰϦͷϝιουͷিಥ ✗ ఆͷিಥ
Duplicated Symbol !!!
None
γϯϘϧͷিಥ໋໊نଇͰ͙͜ͱ͕Ͱ͖Δ ʢେͷ߹ʣ
1.1.1.Ϋϥεͷ໋໊نଇ
✓ 3จࣈͷେจࣈprefixΛ͚ͭΔ @interface ISHObject : NSObject ! @end
Objective-CʹΑΔϓϩάϥϛϯά (p.127) “ಠࣗͷΫϥεʹ3จࣈͷϓϨϑΟοΫεΛ͚͍ͭͯͩ͘͞ɻ ձ໊ࣾ ΞϓϦέʔγϣϯ໊ʹͪͳΜͩͷͰɺॏཁͳίϯϙʔωϯτʹ ༝དྷ͢ΔͷͰߏ͍·ͤΜɻ” “ͨͱ͑ɺձ໊͕ࣾWhispering Oakɺ։ൃ͢ΔήʔϜͷ໊લ͕Zebra SurpriseͰ͋Εɺ WZSWOZͱ͍ͬͨϓϨϑΟοΫεʹ͢ΔͱΑ͍
͔͠Ε·ͤΜɻ”
Objective-CʹΑΔϓϩάϥϛϯά (p.126) “2จࣈͷϓϨϑΟοΫεɺϑϨʔϜϫʔΫΫϥεʹ͏ͨΊɺ Apple͕༧͍ͯ͠·͢ɻ” ✗ IS ✓ NJK
1.1.2.ΧςΰϦͷϝιουͷ໋໊نଇ
✓ 3จࣈͷখจࣈprefixΛ͚ͭΔ @interface NSObject (ISHAdditions) ! - (void)ish_additionalMethod; ! @end
Objective-CʹΑΔϓϩάϥϛϯά (p.74) “Ϋϥε໊ͷϓϨϑΟοΫεͱಉ͡3จࣈͷจࣈྻΛɺϝιου໊ ͷنʹैͬͯখจࣈʹ͠ɺΞϯμʔείΞΛ͞ΜͰϝιου ໊ͱ࿈͍݁ͯͩ͘͠͞ɻ” “ಈ࡞͕ෆఆʹͳΔ͜ͱΛճආ͢ΔͨΊɺϑϨʔϜϫʔΫΫϥε ʹΧςΰϦΛఆٛͯ͠ϝιουΛՃ ͢Δࡍɺ໊લʹϓϨ ϑΟοΫεΛ͚ͭΔΑ͏ʹ͢ΔͱΑ͍Ͱ͠ΐ͏ɻ”
App Library methodA methodA ͲͪΒͷmethodAͷ࣮͕࣮ߦ͞ΕΔͷ͔ෆఆ
App Library methodA ish_methodA
1.1.3.ఆͷ໋໊نଇ
✓ ؔ࿈͢ΔΫϥε໊Λ಄ʹ͚ͭΔ extern NSString *const ISHObjectGlobalConstant; ! @interface ISHObject :
NSObject ! @end ISHObject.h ISHObject.m NSString *const ISHObjectGlobalConstant = @"Foo"; ! @implementation ISHObject ! @end
✓ ֎෦͔Βෆཁͳఆඇެ։ʹ͢Δ ISHObject.m static NSString *const ISHLocalConstant = @"Foo"; !
@implementation ISHObject ! @end
1.1.4.Α͋͘ΔγϯϘϧͷিಥ
ϥΠϒϥϦ͕ґଘ͢ΔϥΠϒϥϦ͕2ॏʹϏϧυλʔήοτʹՃ͞Ε͍ͯΔ Library A Library B Library C Library C
ϥΠϒϥϦ͕ϥΠϒϥϦʹґଘ͢Δ͜ͱѱ͍͜ͱͰ ͳ͍͕ɺར༻ଆͰিಥ͕ى͖ͳ͍Α͏ʹཹҙ͢Δ͖
✓ ֎෦ͷϥΠϒϥϦʹґଘ͢Δ͜ͱΛ໌ه͢Δ ✓ CocoaPodsͳͲͷґଘཧΛਪ͢Δ
None
1.1.Ϧιʔεͷিಥ
దʹϥΠϒϥϦͷϦιʔεΛѻ͏ͱ ར༻͢ΔΞϓϦͷϦιʔεͱিಥ͢Δ
[UIImage imageNamed:@"Foo"]; NSLocalizedString(@"Foo", nil);
NSBundle *bundle = [NSBundle mainBundle]; NSString *filePath = [bundle pathForResource:@"foo"
ofType:@"png"]; [UIImage imageWithContentsOfFile:filePath]; NSBundle *bundle = [NSBundle mainBundle]; [bundle localizedStringForKey:@"foo" value:@"" table:nil]; ϝΠϯόϯυϧͷϦιʔεΛಡΜͰ͍Δ
main bundle foo.png foo.png foo.pngmain bundleʹ1ݸ͔͠ଘࡏͰ͖ͳ͍ ? App Library
Main bundle foo.png foo.png ϥΠϒϥϦ༻ʹbundleΛͭ͘Εղܾ Library bundle
✓ ϝΠϯόϯυϧʹΞΫηε͢Δͷʹҙ ✓ ϦιʔεϥΠϒϥϦઐ༻ͷNSBundleʹೖΕΔ
None
2.ྑ͍ @Interface
✓ Θ͔Γ͍͢
✓ ࣮ΛਪଌͰ͖Δ ✓ ޡ༻Λͤ͞ͳ͍
@interface ISHCache : NSObject ! @property (nonatomic) NSUInteger size; @property
(nonatomic) NSUInteger limit; ! - (id)get:(id)key; - (void)set:(id)object key:(id)key; - (void)remove:(id)key; - (void)removeAll; ! @end ✗
@interface ISHCache : NSObject ! @property (nonatomic, readonly) NSUInteger currentSize;
@property (nonatomic, readwrite) NSUInteger sizeLimit; ! - (id)objectForKey:(id)key; - (void)setObject:(id)object forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; ! @end ✓
✓ ྑ͍ @property ✓ ྑ͍௨ύλʔϯ τϐοΫແݶ͋Δ͕ಛʹॏཁͳ2ͭ
2.1.ྑ͍ @property
✓ มߋͷՄ൱Λ໌֬ʹ͢Δ ✓ ϥΠϒϥϦͷར༻ʹඞཁͳใ༩͑Δ ✓ ϥΠϒϥϦͷར༻ʹෆཁͳใΛ༩͑ͳ͍
1.1.3.readwrite vs readonly
readwrite ✓ มߋ͢Δඞཁ͕͋ΔϓϩύςΟ
readwrite ͍͔ͳΔλΠϛϯάʹมߋ͞Εͯ ΦϒδΣΫτͷ߹ੑΛอͯΔ͜ͱ͕·͍͠
ྫ
@interface ISHCache : NSObject ! @property (nonatomic, readonly) NSUInteger currentSize;
@property (nonatomic, readwrite) NSUInteger sizeLimit; ! - (id)objectForKey:(id)key; - (void)setObject:(id)object forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; ! @end currentSize < sizeLimit
- (void)setSizeLimit:(NSUInteger)sizeLimit { _sizeLimit = sizeLimit; ! if (self.currentSize >
sizeLimit) { [self removeAllObjects]; } } currentSize < sizeLimit ΛอͭͨΊʹ͜ͷΑ͏ͳ࣮͕ظ͞ΕΔ NSCache͜͏͍͏ڍಈʹͳ͍ͬͯΔ
readwrite ͍͔ͳΔλΠϛϯάʹมߋ͞Εͯ ΦϒδΣΫτͷ߹ੑΛอͯΔ͜ͱ͕·͍͠
͜͏͍࣮͕ͬͨ໘Ͱɺ ͦͦมߋ͢Δඞཁͳ͍߹?
readonly ✓ มߋ͢Δඞཁ͕ͳ͍ϓϩύςΟ ✓ มߋΛېࢭ͍ͨ͠ϓϩύςΟ
readonly มߋΛؾʹ͠ͳͯ͘ࡁΉ
ྫ
@interface ISHCache : NSObject ! @property (nonatomic, readonly) NSUInteger currentSize;
@property (nonatomic, readonly) NSUInteger sizeLimit; ! - (instancetype)initWithSizeLimit:(NSUInteger)sizeLimit; ! - (id)objectForKey:(id)key; - (void)setObject:(id)object forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; ! @end
- (instancetype)initWithSizeLimit:(NSUInteger)sizeLimit { self = [super init]; if (self) {
_sizeLimit = sizeLimit; } return self; } มߋͰ͖ͳ͍ΘΓʹॳظԽ࣌ʹΛ͢
·ͱΊΔͱ
readwrite ✓ มߋ͢Δඞཁ͕͋ΔϓϩύςΟ ✓ มߋ͞Εͯ߹ੑ͕อͨΕΔ readonly ✓ มߋ͢Δඞཁ͕ͳ͍ϓϩύςΟ ✓ มߋΛېࢭ͍ͨ͠ϓϩύςΟ
None
2.2.ྑ͍௨ύλʔϯ
✓ blocks ✓ delegate ✓ NSNotification ✓ KVO
2.2.1.blocks
✓ ௨͕ಛఆͷϝιουʹ݁ͼͭ͘ ✓ ௨ͷछྨ͕গͳ͍߹ ద͍ͯ͠Δέʔε UIDocument *document; [document openWithCompletionHandler:^(BOOL success)
{ // completed }];
✓ Ҿʹ݁ՌΛ͢ ✓ Τϥʔ͕ఆ͞ΕΔ߹NSError͢ ࡞๏ GKTurnBasedMatch *match; [match acceptInviteWithCompletionHandler:^(GKTurnBasedMatch *match,
NSError *error) { ; }];
blocksͷߏจҟ༷ʹෳࡶ
None
✓ http://fuckingblocksyntax.com ✓ Ѫ͕͋Εͳ͍
2.2.2.delegate
✓ ௨͕ಛఆͷΦϒδΣΫτʹ݁ͼͭ͘ ✓ ௨ͷछྨ͕ଟ͍ ✓ ௨ͷड͚ख͕1͔ͭ͠ͳ͍ ద͍ͯ͠Δέʔε @optional ! -
(void)scrollViewDidScroll:(UIScrollView *)scrollView; - (void)scrollViewDidZoom:(UIScrollView *)scrollView; - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; ໋໊نଇʹ͍ͭͯCocoa͚ίʔσΟϯάΨΠυϥΠϯ, p.15Λࢀর
2.2.3.NSNotification
✓ ௨ͷड͚ख͕ଟ͍ ✓ ௨ͷૹ৴ݩͱड͚ख͕ԕ͍ͱ͖ ద͍ͯ͠Δέʔε άϩʔόϧͳ௨ʹͳΔͷͰ҆қʹ࠾༻ͤͣɺ ઌʹdelegate, BlocksͰ࣮ݱͰ͖ͳ͍͔ݕ౼͢Δɻ
2.3.ྑ͍@interface·ͱΊ
✓ దࡐదॴ readwrite readonly ✓ blocks ✓ delegate ✓ NSNotification
✓ KVO
None
3.Ϣχοτςετ
3.1.ςετΛॻ͘ཧ༝
ςετΛॻ͍ͨํ͕։ൃ͕͍Օॴ͕͋Δ (σϞΞϓϦͰσόοά͢ΔΑΓ)
@interface ISHCache : NSObject ! @property (nonatomic, readonly) NSUInteger currentSize;
@property (nonatomic, readwrite) NSUInteger sizeLimit; ! - (id)objectForKey:(id)key; - (void)setObject:(id)object forKey:(id)key; - (void)removeObjectForKey:(id)key; - (void)removeAllObjects; ! @end
- (void)testSetObjectForKey { id object = [[NSObject alloc] init]; id
key = @"foo"; ! [cache setObject:object forKey:key]; ! XCTAssertEqual(cache.currentSize, 1U); XCTAssertEqualObjects([cache objectForKey:key], object); }
✓ setObject:forKey:ͷ࣮ߦ࣌ʹsizeLimitΛ͑Δ߹ʁ ✓ setObject:forKey:ͷ࣮ߦޙʹsizeLimitΛখͨ͘͞͠߹ʁ ✓ removeAllObjectsͷ࣮ߦޙͷcurrentSizeʁ ͱ͍͏݅ΛσϞΞϓϦ্Ͱຖճσόοά͢ΔඇৗʹͭΒ͍͕ɺ Ϣχοτςετ1ॻ͚܁Γฦ࣮͠ߦͰ͖Δɻ
ίʔυ͕յΕ͍ͯΔ͜ͱΛ͙͢ʹൃݟͰ͖Δ ظʹΘͨͬͯෳਓ͕ϝϯςφϯε͢ΔϓϩάϥϜյΕ͍͢ ςετϓϩάϥϜ͕ਖ਼͍͜͠ͱͷূ໌Ͱͳ͍
✓ setObject:forKey:ͷ࣮ߦ࣌ʹsizeLimitΛ͑Δ߹ʁ ✓ setObject:forKey:ͷ࣮ߦޙʹsizeLimitΛখͨ͘͞͠߹ʁ ✓ removeAllObjectsͷ࣮ߦޙͷcurrentSizeʁ ͲΕ͔1͚ͭͩյΕͨ͜ͱΛσϞΞϓϦ্Ͱ ݕ͢Δ͜ͱ͍͕͠ɺϢχοτςετͳΒ؆୯
ϥΠϒϥϦͷςετͷϝϦοτ ίετʹݟ߹͏͜ͱ͕ଟ͍ ΞϓϦͱൺ༷ͯมߋ͕͘͢ͳ͍ͷͰɺ ςετίʔυ͕ΰϛʹͳΔ͕͍֬
ϥΠϒϥϦʹର͢ΔϢχοτςετΛॻ͘ཧ༝े
3.2.CIΛಋೖ͢Δ
͔ͤͬ͘ςετΛॻ͍ͨͷͰ࣮֬ʹ࣮ߦ͍ͨ͠ git pushͷલʹඞͣςετΛ࣮ߦͰ͖Δਓؒগͳ͍
Git repository CI server Developer git push git hook Build
report CI
git push͢ΔͱΕͳ͘Ϩϙʔτ͕Β͑ΔΈ ✓ ϏϧυͰ͖Δ͔ʁ ✓ ςετ௨͔ͬͨʁ ✓ ίʔυΧόϨοδʁ
3.2.1.CIͷηοτΞοϓ
࠷ϧʔτ: λʔϛφϧ͔ΒϏϧυͰ͖ΔΑ͏ʹ
xcodebuild clean test \ -sdk iphonesimulator \ -workspace ISDiskCache.xcworkspace \
-scheme ISDiskCache \ -configuration Debug \ -destination "name=iPhone Retina (4-inch),OS=7.0" ཁ͢ΔʹΫϦʔϯͯ͠ςετͯ͠ͶͬͯίϚϯυ ͋ͱ͜ΕΛCIαʔόʔʹ͑Δ͚ͩͰOK
3.2.2.WebαʔϏε
CI αʔϏε
Git repository CI server Developer git push git hook Build
report
GitHub Developer git push git hook Build report
✓ public repositoryແྉ ✓ GitHub࿈ܞ ✓ status badge
֘ίϛοτͷϏϧυͷঢ়ଶ͕Θ͔Δ !!!
ίʔυΧόϨοδදࣔαʔϏε
֘ίϛοτͷίʔυΧόϨοδ͕Θ͔Δ
GitHub Developer git push git hook Build report Coverage report
✓ public repositoryແྉ ✓ GitHub࿈ܞ ✓ status badge
྆ํηοτΞοϓ͢Δͱ͜Μͳײ͡
https://github.com/ishkawa/ISDiskCache/
3.3.Ϣχοτςετ·ͱΊ
✓ ςετͷಋೖͰ։ൃ͕͘ͳΔՕॴ͋Δ ✓ յΕͨՕॴΛൃݟ͘͢͠ͳΔ ✓ ϥΠϒϥϦͷςετΞϓϦͷςετΑΓߴCP ✓ CIͰৗʹςετ͞Εͨঢ়ଶΛอͭ͜ͱ͕Ͱ͖Δ
None
·ͱΊ
1.ಋೖઌͷΞϓϦͱͷিಥʹؾΛ͚ͭΔ 2.ଞਓʹΘ͔Γ͍͢ΠϯλʔϑΣʔεʹ͢Δ 3.࣭͕མͪʹ͍͘ΈΛಋೖ͢Δ ϥΠϒϥϦΛެ։͢Δͱ͖….