Skip to content

Instantly share code, notes, and snippets.

View casademora's full-sized avatar

Saul Mora casademora

View GitHub Profile
*.pbxproj -crlf -diff -merge
select * from zepisode e
where zqueueOrder =
(
select min(zqueueOrder) from zepisode f where e.z_pk = e.z_pk
)
@casademora
casademora / gist:1067256
Created July 6, 2011 13:47
Regenerate Core Data files in an Xcode project
## Add this as a 'Run Script' step in your Xcode Project prior to the compile step
mogen=`which mogenerator`
if [[ -x $mogen ]]; then
echo "Updating data objects using $mogen"
cd "$PROJECT_DIR/Model" && $mogen -m MyProject.xcdatamodeld/MyProject.xcdatamodel -M ./generated -H ./entities
fi
@casademora
casademora / gist:3156384
Created July 21, 2012 16:45
performSelector without ARC compiler warnings
- (id) performSelectorWithoutWarning:(SEL)selector;
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [self performSelector:selector];
#pragma clang diagnostic pop
}
# Common Save Patterns
Create in Background
Save and Wait
Save with Block
@casademora
casademora / gist:5665451
Created May 28, 2013 19:34
Simple each: category on NSArray, or NSSet
- (void) mgp_each:(void(^)(id))objectMap;
{
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
objectMap(obj);
}];
}
@implementation NSNumber (PandaHelpers)
- (void) mgp_times:(void(^)(NSInteger))thingToDo;
{
NSAssert(thingToDo, @"No operation to perform");
for (NSInteger i = 0; i < [self integerValue]; i++)
{
thingToDo(i);
}
@casademora
casademora / gist:d06e69288fb24c9ace6e
Created July 14, 2014 15:20
Extension to writeTo NSOutputStream
extension String
{
func writeTo(outputStream:NSOutputStream)
{
if let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
{
let bytes = ConstUnsafePointer<UInt8>(data.bytes)
outputStream.write(bytes, maxLength: data.length)
}
}
@casademora
casademora / gist:40b960d49e057ecb3684
Last active August 29, 2015 14:04
Managed Object initializer
class CustomObject : NSManagedObject
{
init(inContext context:NSManagedObjectContext = SingletonContextStorage.context)
{
let klass = CustomObject.self
let entity = NSEntityDescription.entityForName(klass.entityName(), inManagedObjectContext: context)
super.init(entity: entity, insertIntoManagedObjectContext: context)
}
}
@casademora
casademora / gist:f115102b2e6530e2554c
Last active September 2, 2015 19:13
Rebuild Core Data Entities Script
#!/bin/sh
## $1 is the path to the model relative to the project dir
## $2 is the name of the model file
##TODO, make the path optional and the model file required
mogen=`which mogenerator`
PlistBuddy=`which PlistBuddy`
if [[ -x $1 ]]; then