This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIStackView { | |
@discardableResult | |
func removeAllArrangedSubviews() -> [UIView] { | |
return arrangedSubviews.reduce([UIView]()) { $0 + [removeArrangedSubViewProperly($1)] } | |
} | |
func removeArrangedSubViewProperly(_ view: UIView) -> UIView { | |
removeArrangedSubview(view) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
we create 2 separate arrays of letters and count | |
the number of characters resulting from the | |
original precedence array. | |
we look up the index of each letter from first letter | |
array and follow the index of the next letter. | |
*/ | |
function findWord(a){ | |
console.log(a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ARC Helper | |
// | |
// Version 2.2 | |
// | |
// Created by Nick Lockwood on 05/01/2012. | |
// Copyright 2012 Charcoal Design | |
// | |
// Distributed under the permissive zlib license | |
// Get the latest version from here: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* We can fetch a record, modify it and then call this save function to save our changes | |
*/ | |
- (BOOL)saveToDb{ | |
NSError *error = nil; | |
BOOL returnVal = ( [[self managedObjectContext] save:&error] ); | |
if(error != nil) | |
NSLog(@"%@", error); | |
return returnVal; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Get all records | |
*/ | |
-(NSArray*)getAllRecordsFromEntity:(NSString *)entity{ | |
NSArray *arr = [self queryDBForEntity:entity predicate:nil sortByField:nil]; | |
//NSLog(@"%@", arr); | |
return arr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Get a record based on the criteria | |
*/ | |
- (id)getRecordFromEntity:(NSString *)entity whereField:(NSString *)fieldName isEqualTo:(id)val | |
{ | |
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %@)", fieldName, val]; | |
//NSLog(@"(P: %@)", [pred predicateFormat]); | |
NSArray *arr = [self queryDBForEntity:entity predicate:pred sortByField:fieldName]; | |
//NSLog(@"%@", arr); | |
if ([arr count] > 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Useful function to check whether a record already exists | |
*/ | |
-(BOOL)doesRecordExistForEntity:(NSString *)entity fieldToCheck:(NSString *)fieldName valueToMatch:(id)val | |
{ | |
NSPredicate *pred = [NSPredicate predicateWithFormat:@"(%K = %@)", fieldName, val]; | |
//NSLog(@"(P: %@)", [pred predicateFormat]); | |
NSArray *arr = [self queryDBForEntity:entity predicate:pred sortByField:fieldName]; | |
//NSLog(@"%@", arr); | |
return ([arr count] > 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Given an object delete it | |
* | |
* @param obj: obj to delete from database | |
* @returns: true if successful in deleting else returns false | |
*/ | |
- (BOOL)deleteObject:(id)obj{ | |
NSError *error; | |
if(obj != nil){ | |
[[self managedObjectContext] deleteObject:obj]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A generic function that inserts a new row for the given entity and fill that row with given key/values | |
*/ | |
-(void)insertObjectForEntity:(NSString *)entityName objectsToInsert:(NSDictionary *)dictObjects | |
{ | |
NSError *error; | |
NSManagedObject *objToInsert = [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:[self managedObjectContext]]; | |
for (id key in [dictObjects allKeys]) { | |
[objToInsert setValue:key forKey:[dictObjects objectForKey:key]]; |
NewerOlder