Skip to content

Instantly share code, notes, and snippets.

View trojanfoe's full-sized avatar

Andy Duplain trojanfoe

  • Wickham, Hampshire, UK.
View GitHub Profile
@trojanfoe
trojanfoe / dateiter.m
Last active January 3, 2016 11:09
Objective-C NSDate example of checking how many times a day-of-the-month appears between two dates. See: http://stackoverflow.com/questions/21161125/how-many-times-a-specific-day-has-passed-between-two-dates Compile with: clang -g -o dateiter dateiter.m -fobjc-arc -framework Foundation
#import <Foundation/Foundation.h>
static void nextMonth(NSDateComponents *comps) {
NSInteger month = [comps month];
if (month == 12) {
[comps setYear:[comps year] + 1];
[comps setMonth:1];
} else {
[comps setMonth:month + 1];
}
$ cat locktest.m
#import <Foundation/Foundation.h>
@interface Locker : NSObject {
NSRecursiveLock *_lock;
}
- (void)setLock:(NSRecursiveLock *)lock;
@end
@implementation Locker
@trojanfoe
trojanfoe / NSArray unrecognized selector exception
Last active December 22, 2015 03:29
NSMutableArray from NSArray copy
#import <Foundation/Foundation.h>
int main(int argc, const char **argv) {
@autoreleasepool {
NSMutableArray *mutableArray;
NSString *str = @"one two three";
mutableArray = [[str componentsSeparatedByString:@" "] copy];
[mutableArray addObject:@"four"];
for (NSString *s in mutableArray) {
NSLog(@"%@", s);