Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Objective-C Programming Guide for Open Source S...

Objective-C Programming Guide for Open Source Software

2014/02/01 @ GREE

Yosuke Ishikawa

February 01, 2014
Tweet

More Decks by Yosuke Ishikawa

Other Decks in Technology

Transcript

  1. IS ISDiskCache ISMemoryCache ISHTTPOperation ISRemoveNull ISPersistentStack ISMethodSwizzling ISBackGesture ISRefreshControl ISColumnsController

    ISRevealController ISCyclicPagesView ISFakeInterfaceOrientation ISInteractiveEdgesNavigationBar ISAlternativeRefreshControl
  2. ✓ ؔ࿈͢ΔΫϥε໊Λ಄ʹ͚ͭΔ extern NSString *const ISHObjectGlobalConstant; ! @interface ISHObject :

    NSObject ! @end ISHObject.h ISHObject.m NSString *const ISHObjectGlobalConstant = @"Foo"; ! @implementation ISHObject ! @end
  3. NSBundle *bundle = [NSBundle mainBundle]; NSString *filePath = [bundle pathForResource:@"foo"

    ofType:@"png"]; [UIImage imageWithContentsOfFile:filePath]; NSBundle *bundle = [NSBundle mainBundle]; [bundle localizedStringForKey:@"foo" value:@"" table:nil]; ϝΠϯόϯυϧͷϦιʔεΛಡΜͰ͍Δ
  4. @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 ✗
  5. @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 ✓
  6. @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
  7. - (void)setSizeLimit:(NSUInteger)sizeLimit { _sizeLimit = sizeLimit; ! if (self.currentSize >

    sizeLimit) { [self removeAllObjects]; } } currentSize < sizeLimit ΛอͭͨΊʹ͜ͷΑ͏ͳ࣮૷͕ظ଴͞ΕΔ NSCache͸͜͏͍͏ڍಈʹͳ͍ͬͯΔ
  8. @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
  9. - (instancetype)initWithSizeLimit:(NSUInteger)sizeLimit { self = [super init]; if (self) {

    _sizeLimit = sizeLimit; } return self; } มߋͰ͖ͳ͍୅ΘΓʹॳظԽ࣌ʹ஋Λ౉͢
  10. ✓ ௨஌͕ಛఆͷΦϒδΣΫτʹ݁ͼͭ͘ ✓ ௨஌ͷछྨ͕ଟ͍ ✓ ௨஌ͷड͚ख͕1͔ͭ͠ͳ͍ ద͍ͯ͠Δέʔε @optional ! -

    (void)scrollViewDidScroll:(UIScrollView *)scrollView; - (void)scrollViewDidZoom:(UIScrollView *)scrollView; - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; ໋໊نଇʹ͍ͭͯ͸Cocoa޲͚ίʔσΟϯάΨΠυϥΠϯ, p.15Λࢀর
  11. @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
  12. - (void)testSetObjectForKey { id object = [[NSObject alloc] init]; id

    key = @"foo"; ! [cache setObject:object forKey:key]; ! XCTAssertEqual(cache.currentSize, 1U); XCTAssertEqualObjects([cache objectForKey:key], object); }
  13. xcodebuild clean test \ -sdk iphonesimulator \ -workspace ISDiskCache.xcworkspace \

    -scheme ISDiskCache \ -configuration Debug \ -destination "name=iPhone Retina (4-inch),OS=7.0" ཁ͢ΔʹΫϦʔϯͯ͠ςετͯ͠ͶͬͯίϚϯυ ͋ͱ͸͜ΕΛCIαʔόʔʹ఻͑Δ͚ͩͰOK