Skip to content

Instantly share code, notes, and snippets.

View tibr's full-sized avatar
🚀

Tim Brückmann tibr

🚀
View GitHub Profile
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 September 18, 2013 12:08
SenTestingKit => XCTestCase exception handling
- (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 August 8, 2013 18:12
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/
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 June 14, 2013 12:56
stub context example
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 March 8, 2012 15:43
Stubbing alloc to return mocked object
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 March 8, 2012 09:42
Setting the do not backup attribute in different iOS versions
@interface NSFileManager (DoNotBackup)
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;
@end