Skip to content

Instantly share code, notes, and snippets.

@hfossli
hfossli / gist:9020767
Last active August 29, 2015 13:56
CYou'll see if you don't use 'copy' in the setter the tests will fail.
@interface MyObject ()
@property (nonatomic, strong) NSString *myStrongString;
@property (nonatomic, copy) NSString *myCopyString;
@end
@implementation MyObject
- (id)init
@hfossli
hfossli / Output
Last active August 29, 2015 13:56
Boolean testing in Objective-C
Untitled.m:13:11: warning: incompatible pointer to integer conversion initializing 'BOOL' (aka 'signed char') with an expression of type 'NSObject *' [-Wint-conversion]
BOOL objExists = obj;
^ ~~~
1 warning generated.
2014-02-18 09:44:10.739 Untitled[46411:507] myBOOL != YES
2014-02-18 09:44:10.741 Untitled[46411:507] Starting void assignPrimitiveToBOOL()
2014-02-18 09:44:10.741 Untitled[46411:507] Failed with value 0
2014-02-18 09:44:10.741 Untitled[46411:507] Failed with value 256
2014-02-18 09:44:10.741 Untitled[46411:507] Failed with value 512
2014-02-18 09:44:10.742 Untitled[46411:507] Failed with value 768
@hfossli
hfossli / code
Last active September 23, 2015 06:51
{
NSString *string = @"123-456-7890";
NSArray *components = [string componentsSeparatedByString:@"-"];
NSLog(@"Components: (%i) %@", (int)components.count, components);
}
{
NSString *string = @"-123-456-7890";
NSArray *components = [string componentsSeparatedByString:@"-"];
NSLog(@"Components: (%i) %@", (int)components.count, components);
}
@hfossli
hfossli / xcode-git-commit-hash-cfbundleversion.rb
Created August 2, 2013 12:27
Run script for Xcode to run after build / archive - updates CFBundleVersion in Info.plist file with short git commit hash
#!/usr/bin/ruby
# xcode-git-commit-hash-cfbundleversion.rb
# Run script for Xcode to run after build / archive
# Updates CFBundleVersion in Info.plist file with short git commit hash
#
# This is based on
# http://github.com/guicocoa/xcode-git-cfbundleversion/
# http://github.com/digdog/xcode-git-cfbundleversion/
# http://github.com/jsallis/xcode-git-versioner
# http://github.com/juretta/iphone-project-tools/tree/v1.0.3
@hfossli
hfossli / IVYApplication.h
Created September 30, 2013 18:09
UIApplication does not send notificaiton wether status bar is hidden or not. This class does!
#import <UIKit/UIKit.h>
extern NSString * const UIApplicationDidHideStatusBarNotification;
@interface IVYApplication : UIApplication
@end
@hfossli
hfossli / main.m
Last active December 25, 2015 20:59
Regex vs componentsSeparatedByCharactersInSet
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSUInteger iterations = 1000000;
{ // Regex
NSTimeInterval timeStart = CFAbsoluteTimeGetCurrent();
NSString *result = nil;
@hfossli
hfossli / DataObject.h
Last active December 31, 2015 20:39
Private, protected and public properties in objective-c
@interface DataObject : NSObject
// public properties
@end
#import "ViewController.h"
@interface Scroll : UIScrollView
@end
@implementation Scroll
- (void)setNeedsLayout
{
#import <libkern/OSAtomic.h>
BOOL ale_dispatch_is_on_queue(dispatch_queue_t queue)
{
int key;
static int32_t incrementer;
CFNumberRef value = CFBridgingRetain(@(OSAtomicIncrement32(&incrementer)));
dispatch_queue_set_specific(queue, &key, value, nil);
BOOL result = dispatch_get_specific(&key) == value;
dispatch_queue_set_specific(queue, &key, nil, nil);

Keybase proof

I hereby claim:

  • I am hfossli on github.
  • I am hfossli (https://keybase.io/hfossli) on keybase.
  • I have a public key ASC8OY-Dk5-RXJKmdCOJ9oHOaBh-LqGHRgg_HoBM4kb6Two

To claim this, I am signing this object: