Skip to content

Instantly share code, notes, and snippets.

View karnlund's full-sized avatar

Kurt Arnlund karnlund

View GitHub Profile
@karnlund
karnlund / CircularQueue.h
Created March 1, 2021 01:28 — forked from werediver/CircularQueue.h
Simple implementation of circular queue in Objective-C (for ARC-enabled environment).
//
// CircularQueue.h
//
// Created on 9/21/13.
//
#import <Foundation/Foundation.h>
@interface CircularQueue : NSObject <NSFastEnumeration>
//
// ViewController.swift
// KeyboardTest
//
// Created by Adam Śliwakowski on 01.12.2015.
// Copyright © 2015 Adam Śliwakowski. All rights reserved.
//
import UIKit
typealias AnimationClosure = (() -> Void)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if defined( DEBUG )
[self dumpNotifications];
#endif
return YES;
}
@karnlund
karnlund / Example.swift
Created February 27, 2017 08:21 — forked from IanKeen/Example.swift
Small utility methods to simplify dealing with Reusable items i.e. table/collection view cells
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut
//Use the extension method to dequeue an instance of the appropriate `Reusable`
class MyVC: UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
tableView
.registerReusable(FooCell.self)
.registerReusable(BarCell.self)
}
@karnlund
karnlund / UIViewFromNib.swift
Last active June 1, 2018 16:20
This is fromNib methods converted for Swift 3. This is obtained from StackOverflow here http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
// This came from StackOverflow
// http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
//
// https://gist.github.com/karnlund/b666acc88532d5f1ca591dd3580605cc
import UIKit
public extension UIView {
public class func fromNib(_ nibName: String? = nil) -> Self? {
return loadFromNib(nibName)
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}
static void dispatch_async_repeated_internal(dispatch_time_t firstPopTime, NSTimeInterval intervalInSeconds, dispatch_queue_t queue, void(^work)(BOOL *stop))
{
dispatch_after(firstPopTime, queue, ^{
BOOL shouldStop = NO;
work(&shouldStop);
if(!shouldStop)
{
dispatch_time_t nextPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(intervalInSeconds * NSEC_PER_SEC));
dispatch_async_repeated_internal(nextPopTime, intervalInSeconds, queue, work);
}
//
// AppDelegate.m
// AnimationExamplesiPhone
//
// Created by Eric Allam on 10/05/2014.
#import "AppDelegate.h"
#pragma mark - UIColor Additions
@karnlund
karnlund / implementation
Last active August 29, 2015 13:57
Extension of NSObject that allows array indexes to be used in KVO key path strings (NSString* personsFriendsName = [obj valueForKeyPathsWithIndexes:@"me.friends[0].name"])
#import "NSObject+ValueForKeyPathWithIndexes.h"
@implementation NSObject (ValueForKeyPathWithIndexes)
-(id)valueForKeyPathWithIndexes:(NSString*)fullPath
{
NSRange testrange = [fullPath rangeOfString:@"["];
if (testrange.location == NSNotFound)
return [self valueForKeyPath:fullPath];
NSArray* parts = [fullPath componentsSeparatedByString:@"."];
@karnlund
karnlund / ExtendedManagedObject.h
Created November 21, 2012 21:32 — forked from vl4dimir/ExtendedManagedObject.h
Added traversal reset that allows a single managed object graph to be converted -(NSDictionary*)toDictionary twice. This is essential if your app is optimized to not fetch the same graph twice.
@interface ExtendedManagedObject : NSManagedObject {
BOOL traversed;
}
@property (nonatomic, assign) BOOL traversed;
- (NSDictionary*) toDictionary;
- (void)resetTraversal; /* allows toDictionary to be called twice on the same managed object graph */
- (void) populateFromDictionary:(NSDictionary*)dict;
+ (ExtendedManagedObject*) createManagedObjectFromDictionary:(NSDictionary*)dict