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
SRE Lounge Hiroshimaへの招待
grimoh
0
250
Agentic AI 時代のテスト手法: Kiro とはじめるプロパティベーステスト (AWS Summit Japan 2026 | DEV212)
ymhiroki
0
210
SRE歴2ヶ月でも開発6年の知見を活かして、チームで止まっていた環境改善を前に進めた話
a_ono
1
210
はじめてのWDM
miyukichi_ospf
1
120
生成AIの活用/high_school2026
okana2ki
0
110
4人目のSREはAgent
tanimuyk
0
390
完全自律ロボットを作りたくて、先に開発を自律させた話(ROS Japan UG #63 LT)
rryz09
0
280
RAGの精度向上とエージェント活用
kintotechdev
2
140
product engineering with qa
nealle
0
150
そのハーネス、本当に境界になっていますか? AIエージェント時代の実行環境設計【MEGU-Meet #4】
cscengineer
PRO
0
120
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
140
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
410
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
How to build a perfect <img>
jonoalderson
1
5.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Building an army of robots
kneath
306
46k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
340
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Designing Experiences People Love
moore
143
24k
RailsConf 2023
tenderlove
30
1.5k
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.࣭͕མͪʹ͍͘ΈΛಋೖ͢Δ ϥΠϒϥϦΛެ։͢Δͱ͖….