Skip to content

Instantly share code, notes, and snippets.

@ketzusaka
ketzusaka / gist:12743fa9d6569dbb447d
Created June 6, 2014 03:38
Swift Operator Overloading Adding << On Array
/*
In Swift, you can overload operators. A common operator in Ruby for working with arrays is <<,
which is syntatic sugar for array.push(). Since Array's in Swift don't take bitwise operations, this is
an example demonstrating adding that operator to an array that contains any type.
As an extra tidbit, I've added >> to prepend an array with an object
*/
@infix func << <T>(inout array: Array<T>, item: T) {
array.append(item)
@davbeck
davbeck / README.md
Last active August 29, 2015 13:57
TNKPropertyKey

It's become common practice to use an @selector for associated objects. This is useful because not only are SELs guaranteed to have a unique address, but because as of Xcode 5, Xcode will warn you when you use a selector that it does not know about. Meaning that it is somewhat protected against spelling mistakes.

This can also be useful when using string keys. For things like state restoration, where you want a key for a given property, you can use the selector for the getter, and get a string from that. Xcode will autocomplete the name for you, and will warn you if you misspell it.

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
    [super encodeRestorableStateWithCoder:coder];
    
 [coder encodeObject:self.feedID forKey:TNKPropertyKey(feedID)];
@uliluckas
uliluckas / gist:3129990
Created July 17, 2012 15:12
mergeChangesFromContextDidSaveNotification with core data bug workarounds
// See http://lists.apple.com/archives/cocoa-dev/2008/Jun/msg00237.html for bugs below
- (void)mergeChangesFromContextDidSaveNotification:(NSNotification*)notification {
NSManagedObject *object;
NSSet* updates;
// Workaround bug 5982319
// Fault in all updated objects because chnages to faults won't trigger fetchedResultsControlle
updates = [notification.userInfo objectForKey:NSUpdatedObjectsKey];
for (object in updates) {
[[self.roManagedObjectContext objectWithID:[object objectID]] willAccessValueForKey:nil];