Skip to content

Instantly share code, notes, and snippets.

View HHuckebein's full-sized avatar

Bernd Rabe HHuckebein

View GitHub Profile
@HHuckebein
HHuckebein / StoryboardRepresentable.swift
Created February 8, 2016 07:46
UIStoryboard extension to load a storyboard by means of a StoryboardRepresentable type
extension UIStoryboard {
class func storyboard(storyboard: StoryboardRepresentable, bundle: NSBundle? = nil) -> UIStoryboard {
return UIStoryboard(name: storyboard.storyboardName, bundle: bundle)
}
}
protocol StoryboardRepresentable {
var storyboardName: String { get }
}
@HHuckebein
HHuckebein / .travis.yml
Created December 12, 2015 11:57
travis-ci.yml file with basic configuration for Swift with Slack integration
language: objective-c
notifications:
slack:
on_success: always
on_failure: change
rooms:
secure: generated-secret
xcode_project: YourProjectName.xcodeproj
xcode_scheme: YourSharedSchemeName
@interface CounterLayer : CALayer
@property (nonatomic, assign) NSInteger count;
@end
@interface MovingCounterView : UIView
@property (nonatomic, strong) CounterLayer *counterLayer;
@end
@implementation DocumentsBrowserTest
{
BOOL _isPad;
SEL realPrepareForSegue, testPrepareForSegue;
}
- (void)setUp
{
[super setUp];
@HHuckebein
HHuckebein / UIViewControllerCategory
Created August 27, 2013 07:15
UIViewController category to for TDD manually triggered segues.
static const char *storyboardSegueKey = "TestAssociatedStoryboardKey";
static const char *senderKey = "TestAssociatedSenderKey";
@implementation YourViewController (Testing)
- (void)documentsBrowserTest_prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
objc_setAssociatedObject(self, storyboardSegueKey, segue, OBJC_ASSOCIATION_RETAIN);
objc_setAssociatedObject(self, senderKey, sender, OBJC_ASSOCIATION_RETAIN);
}
@HHuckebein
HHuckebein / MethodSwizzling
Created August 27, 2013 07:10
Helper method for method swizzling. Don't forget to import #import <objc/runtime.h>.
+ (void)swapInstanceMethodsForClass:(Class)cls selector:(SEL)sel1 andSelector:(SEL)sel2
{
Method method1 = class_getInstanceMethod(cls, sel1);
Method method2 = class_getInstanceMethod(cls, sel2);
method_exchangeImplementations(method1, method2);
}
@HHuckebein
HHuckebein / Test_UIBarButtonItemSegue
Created August 27, 2013 06:55
Testing the infoBarButtonItem objects segue connection. Here it should be named after the string "InfoVCSegue"
- (void)test_infoBarButtonItemSegue
{
// then
UIBarButtonItem *button = [self.sut infoBarButtonItem];
SEL selector = [button action];
assertThat(NSStringFromSelector(selector), is(equalTo(@"perform:")));
id target = [button target];
assertThat(NSStringFromClass([[target class] superclass]), is(equalTo(@"UIStoryboardSegueTemplate")));
@HHuckebein
HHuckebein / test_ManuallyTriggeredSegueIsConnected
Created August 27, 2013 06:50
Test if a manually triggered segue is connected. The convention for segue names are always follows the pattern view controller class name appended by the string "Segue".
- (void)test_ExamplesVCSegueConnected
{
STAssertNoThrow([self.sut performSegueWithIdentifier:[[self appDelegate] segueIdentifierForClass:[ExamplesVC class]] sender:self], @"ExamplesVC should be connected");
}
@HHuckebein
HHuckebein / GistCommunicationManager.h
Created June 10, 2013 09:33
A pattern for implementing a class managing a NSOperationQueue and NSOperations. The files attached show how to apply this pattern to downloading gists/gravatar images from github.com
//
// GistCommunicationManager.h
// GistExplorer
//
// Created by Bernd Rabe on 28.05.13.
// Copyright (c) 2013 RABE_IT Services. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "OperationDelegate.h"
@HHuckebein
HHuckebein / UITabBarControllerSequence.m
Created April 8, 2013 08:24
Initialize the sequence of UITabBarControllers read for userdefaults
//
//
//
//
// Created by Bernd Rabe on 07.08.12.
// Copyright (c) 2012 RABE_IT Services. All rights reserved.
//
#pragma mark - TabBarController Sequence