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 / CGFloatEqual.m
Created May 14, 2014 11:24
CGFloatEqual
BOOL CGFloatEqual(CGFloat a, CGFloat b, CGFloat accuracy)
{
#if CGFLOAT_IS_DOUBLE
if (fabs(a-b) < accuracy * DBL_EPSILON * fabs(a+b) || fabs(a-b) < DBL_MIN)
{
return YES;
}
#else
if (fabs(a-b) < accuracy * FLT_EPSILON * fabs(a+b) || fabs(a-b) < FLT_MIN)
{
@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);
}
#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);
@hfossli
hfossli / NodeTask.swift
Last active January 2, 2024 00:27
Start a node.js server using NSTask in Swift.
import Foundation
import Cocoa
class NodeTask: NSObject {
private let processIdentifier = NSProcessInfo.processInfo().processIdentifier
private let nodeTask = NSTask()
private let readPipe = NSPipe()
private let errorPipe = NSPipe()
private let queue = dispatch_queue_create("NodeTask.output.queue", DISPATCH_QUEUE_SERIAL)

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:

CATransaction.begin()
CATransaction.setCompletionBlock({
// Every animation added to this transaction is now finished
})
UIView.animateWithDuration(0.5, delay: 0.5, options: [], animations: {
view1.alpha = 1.0
}, completion: { finished in
self.addSeveralLayerAnimations()
})
@hfossli
hfossli / RACSignalTest.m
Created September 23, 2016 19:54
Improving setNameWithFormat: in RAC
#import <XCTest/XCTest.h>
@interface RACSignal : NSObject
- (instancetype)someOperatorWithObject:(NSObject *)object;
- (NSString *)name;
@end