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
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
5分でわかるDuckDB Quack
chanyou0311
4
310
product engineering with qa
nealle
0
140
“ID沼入口” - 基本とセキュリティから始める、考え続けるためのID管理技術勉強会 告知&イントロ
ritou
0
390
5分でわかる Amazon Connect_20260608
hwangbyeonghun
0
180
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
140
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
190
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
800
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
5
1.7k
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
380
AIエージェントとPhysical AIが拓く製造業の変革(ハノーバーメッセリキャップ)
iotcomjpadmin
0
210
そのハーネス、本当に境界になっていますか? AIエージェント時代の実行環境設計【MEGU-Meet #4】
cscengineer
PRO
0
110
Baseline対応のDOMの型定義を作った
uhyo
3
680
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
380
Evolving SEO for Evolving Search Engines
ryanjones
0
230
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
340
The Invisible Side of Design
smashingmag
301
52k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
170
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
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.࣭͕མͪʹ͍͘ΈΛಋೖ͢Δ ϥΠϒϥϦΛެ։͢Δͱ͖….