Skip to content

Instantly share code, notes, and snippets.

Håvard Fossli hfossli

View GitHub Profile
@hfossli
hfossli / gist:9020767
Last active Aug 29, 2015
CYou'll see if you don't use 'copy' in the setter the tests will fail.
View gist:9020767
@interface MyObject ()
@property (nonatomic, strong) NSString *myStrongString;
@property (nonatomic, copy) NSString *myCopyString;
@end
@implementation MyObject
- (id)init
@hfossli
hfossli / Output
Last active Aug 29, 2015
Boolean testing in Objective-C
View Output
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
View code
{
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 Aug 2, 2013
Run script for Xcode to run after build / archive - updates CFBundleVersion in Info.plist file with short git commit hash
View xcode-git-commit-hash-cfbundleversion.rb
#!/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 Sep 30, 2013
UIApplication does not send notificaiton wether status bar is hidden or not. This class does!
View IVYApplication.h
#import <UIKit/UIKit.h>
extern NSString * const UIApplicationDidHideStatusBarNotification;
@interface IVYApplication : UIApplication
@end
@hfossli
hfossli / main.m
Last active Dec 25, 2015
Regex vs componentsSeparatedByCharactersInSet
View main.m
#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 Dec 31, 2015
Private, protected and public properties in objective-c
View DataObject.h
@interface DataObject : NSObject
// public properties
@end
@hfossli
hfossli / ffmpeg_split.sh
Last active Jan 9, 2016
A bash / shell script for splitting videos / movies into several / multiple files using ffmpeg
View ffmpeg_split.sh
#!/bin/bash
# Created by Håvard Fossli <hfossli@gmail.com> in 2013
# Derived from Alexis Bezverkhyy <alexis@grapsus.net> in 2011
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
#
# Description
# A bash script for splitting videos into several files using ffmpeg.
#
View Code
#import "ViewController.h"
@interface Scroll : UIScrollView
@end
@implementation Scroll
- (void)setNeedsLayout
{
View Alternative 1
#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);
You can’t perform that action at this time.