Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Tim Brückmann tibr

🚀
View GitHub Profile
View gist:441ea71c8c0fd69bca58
func fetchNotificationsNotMatchingEtag(etag: String?, includeReadNotifications includeRead: Bool, updatedSince since: NSDate?) -> SignalProducer<OCTResponse, NSError> {
let signal = fetchNotificationsNotMatchingEtag(etag, includeReadNotifications: includeRead, updatedSince: since)
return signal.toSignalProducer()
|> map { $0 as! OCTResponse }
}
@tibr
tibr / XCTestCase+OCUnitCompatibility.m
Created Sep 18, 2013
SenTestingKit => XCTestCase exception handling
View XCTestCase+OCUnitCompatibility.m
- (void)failWithException:(NSException *)exception
{
NSRange firstColonRange = [exception.reason rangeOfString:@":"];
NSString *filename = [exception.reason substringToIndex:firstColonRange.location];
NSString *secondPart = [exception.reason substringFromIndex:firstColonRange.location + firstColonRange.length];
NSRange lineSeparatorRange = [secondPart rangeOfString:@" "];
NSString *lineString = [secondPart substringToIndex:lineSeparatorRange.location];
@tibr
tibr / gist:6187127
Created Aug 8, 2013
UIScrollView needs a subview with an absolute width value to use it's full width as contentSize. I'm trying to use a helper view here to make sure it always uses it's own width as it's content width. https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/
View gist:6187127
UIView *scrollViewWidthEnforcer = [UIView new];
[scrollViewWidthEnforcer setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.scrollView addSubview:scrollViewWidthEnforcer];
[self.scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[enforcer(==scrollView)]|"
options:0
metrics:nil
views:@{
@"enforcer" : scrollViewWidthEnforcer,
@"scrollView" : self.scrollView
}]];
@tibr
tibr / gist:5781595
Created Jun 14, 2013
stub context example
View gist:5781595
context(@"success", ^{
beforeEach(^{
[OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request) {
NSString *expectedPath = @"/3/configuration";
BOOL shouldStub = [[request.URL path] isEqualToString:expectedPath];
return shouldStub;
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
OHHTTPStubsResponse *response = [OHHTTPStubsResponse responseWithFile:@"configuration.json"
contentType:@"application/json"
@tibr
tibr / gist:2001574
Created Mar 8, 2012
Stubbing alloc to return mocked object
View gist:2001574
it(@"should start the processing with the ids from the network response", ^{
// mock network request
[KWSpec canResponseJSON:@"ids"];
// execute code under test
[client syncMyStuff];
// create mock
id process = [ProcessingOperation mock];
// return mock by stubbing alloc
@tibr
tibr / NSFileManager+DoNotBackup.h
Created Mar 8, 2012
Setting the do not backup attribute in different iOS versions
View NSFileManager+DoNotBackup.h
@interface NSFileManager (DoNotBackup)
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;
@end