Skip to content

Instantly share code, notes, and snippets.

View paulrehkugler's full-sized avatar

Paul Rehkugler paulrehkugler

View GitHub Profile
- (UIStatusBarStyle) preferredStatusBarStyle {
// UIStatusBarStyleLightContent is only defined in the iOS7 SDK
#if __IPHONE_OS_MAX_ALLOWED 70000
return UIStatusBarStyleLightContent;
#else
return UIStatusBarStyleBlackOpaque;
#endif
}
#endif
- (id)initWithCancelButtonTitle:(NSString *)cancelTitle otherButtonTitles:(NSString *)otherButtonTitles, ... {
if (self = [super init]) {
NSMutableArray *buttonTitles = [[NSMutableArray alloc] init];
BRYEachArgumentBlock eachArgumentBlock = ^(NSString *title) {
[buttonTitles addObject:title];
};
BRYVarArgs(eachArgumentBlock, otherButtonTitles);
}
/* MyModelObject.h */
@interface MyModelObject : NSObject
// this data is "publicly" immutable
@property (nonatomic, readonly) NSArray *someData;
@end
@paulrehkugler
paulrehkugler / gist:9360998
Last active August 29, 2015 13:57
Proper string format tokens for NSInteger, NSUInteger, and CGFloat... Ewww
- (BRYDescriptionBuilder *)appendInteger:(NSInteger)integer withName:(NSString *)name {
#if defined(__LP64__) && __LP64__
return [self appendString:[NSString stringWithFormat:@"%li", integer] withName:name];
#else
return [self appendString:[NSString stringWithFormat:@"%i", integer] withName:name];
#endif
}
- (BRYDescriptionBuilder *)appendUnsignedInteger:(NSUInteger)unsignedInteger withName:(NSString *)name {
#if defined(__LP64__) && __LP64__
//
// NSObject+PRKeyValueObserving.h
// PRKeyValueObserving
//
// Created by Paul Rehkugler on 3/8/14.
// Copyright (c) 2014 Paul Rehkugler. All rights reserved.
//
#import <Foundation/Foundation.h>
@paulrehkugler
paulrehkugler / MacroFailure.m
Created March 12, 2014 18:37
Macro fails when NSArray literals (i.e. @[]) aren't wrapped in parentheses (i.e. (@[])).
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
#define IOS7_CODE_WITH_FALLBACK(iOS7_code, other_code) \
do { \
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {\
iOS7_code \
}\
else { \
other_code \
} \
@paulrehkugler
paulrehkugler / gist:9647085
Created March 19, 2014 17:37
Default Protocol Method Implementation in Objective-C
// SomeProtocol.h
@protocol SomeProtocol <NSObject>
- (void) protocolMethod;
@end
// NSObject+SomeProtocolDefaultImplementation.h
@interface NSObject(SomeProtocolDefaultImplementation)
@interface UINavigationController(Completion)
- (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(void (^)(void))completion;
@end
@paulrehkugler
paulrehkugler / Nope.m
Created April 18, 2014 20:48
Block Pointer - Doesn't work
// trying to make a block pointer
typedef void (^DoingBadStuffWithBlocks)();
DoingBadStuffWithBlocks *theCompilerHatesThis = &^{
if (false)
{
*theCompilerHatesThis();
}
}();
@paulrehkugler
paulrehkugler / RecursiveBlock.m
Last active November 7, 2024 18:16
Recursive Block
// Follow up to - https://gist.github.com/paulrehkugler/11063725
BOOL baseCaseCondition = NO; // obviously this should be data driven, not hardcoded
typedef void (^RecursiveBlock)(void (^)());
RecursiveBlock aRecursiveBlock;
aRecursiveBlock = ^(RecursiveBlock block){
if ((baseCaseCondition) && block)
{