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

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Objective-C Programming Guide for Open Source Software

2014/02/01 @ GREE

Yosuke Ishikawa

February 01, 2014

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

118 slides
  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. ྫ

  7. @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
  8. - (void)setSizeLimit:(NSUInteger)sizeLimit { _sizeLimit = sizeLimit; ! if (self.currentSize >

    sizeLimit) { [self removeAllObjects]; } } currentSize < sizeLimit ΛอͭͨΊʹ͜ͷΑ͏ͳ࣮૷͕ظ଴͞ΕΔ NSCache͸͜͏͍͏ڍಈʹͳ͍ͬͯΔ
  9. ྫ

  10. @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
  11. - (instancetype)initWithSizeLimit:(NSUInteger)sizeLimit { self = [super init]; if (self) {

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

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

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

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

More Decks by Yosuke Ishikawa

Other Decks in Technology