Skip to content

Instantly share code, notes, and snippets.

View benvium's full-sized avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / NSManagedObject+CALDeleteAll.h
Created February 13, 2015 14:41
Delete all instances of an NSManagedObject from CoreData.
@import CoreData;
#import <Foundation/Foundation.h>
@interface NSManagedObject (CALDeleteAll)
/**
* Deletes all instances of this object from CoreData (may take a while)
*/
+ (void)cal_deleteAll:(NSManagedObjectContext *)context;
@benvium
benvium / android-studio-unit-test-setup
Created February 20, 2015 13:25
How to set up Android Studio for Unit Testing. Works in version 1.0 and up.
In Android Studio 1.0 the scheme has changed a little bit.
The path to a unit test source file should be (app)/src/androidTest/java/com/mycompany/myapp/HelloWorldTest.java
Here's how I set up Unit Tests in a new Android Studio project:
- Open app in Android Studio.
- Set the Project explorer (left hand window) to display 'Project' mode. Tap the little drop-down at the top left and select 'Project'.
- Right click the 'src' directory, 'New -> Directory'.
- Call new directory androidTest
[
{
"name":"Alice",
"age": 64
},
{
"name":"Bob",
"age": 12
},
{
@benvium
benvium / JSONFromBundle.h
Created May 21, 2015 16:32
Simple class to read a json file from the bundle. Works in unit tests or a 'real' app.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface JSONFromBundle : NSObject
// Also removes nulls
+ (id)nameNoExtension:(NSString *)name;
@end
@benvium
benvium / RealmTestCase.h
Created May 21, 2015 16:34
Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests
#import <XCTest/XCTest.h>
// Inherit from this to automatically create and delete [RLMRealm defaultRealm] files between tests
@interface RealmTestCase : XCTestCase
@end
@benvium
benvium / Realm_Unit_Testing_Podfile
Last active August 29, 2015 14:21
Podfile demonstrating how to set up Realm for XCTest Unit Testing.
# Put then name of your main app's target here.
target 'MainApp' do
pod 'Realm'
pod 'NSDate+Calendar'
pod 'Realm+JSON'
# and any other dependencies
end
# Put the name of the Unit Testing Target here
target 'MainAppTests' do
@benvium
benvium / NSMutableDictionary+BVMNullReplacement.h
Last active August 29, 2015 14:21
In-place removal of [NSNull null] values in collections.Useful when importing JSON data into realm-cocoa. Note that the whole structure must be Mutable (e.g. all child collections are NSMutableArray or NSMutableDictionary)
@import Foundation;
// In-place removal of [NSNull null] values
// Useful when importing into Realm
@interface NSMutableDictionary (BVMNullReplacement)
- (void)bvm_removeNulls;
@end
// In-place removal of [NSNull null] values
// Useful when importing into Realm
@benvium
benvium / FetchResultsTableViewUpdater.h
Created May 26, 2015 14:11
Implements the boilerplate required to update a UITableView based on results from an NSFetchedResultsController
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@import CoreData;
typedef NS_ENUM(NSUInteger, FetchResultControllerMode) {
FetchResultsTableViewUpdaterModeMultipleSection,
FetchResultsTableViewUpdaterModeSingleFixedSection
};
@benvium
benvium / MagicalRecordTestCase.h
Last active August 29, 2015 14:22
Inherit TestCase classes from this to setup and tearDown a SQLite-backedMagicalRecord core data stack on each test.The SQLite file itself will be deleted between runs.Test cases should use the context provided on self.context. Note that this has taken many tries to get right! Just deleting the files sometimes resulted in the data being retained …
#import <XCTest/XCTest.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/**
Inherit XCTest TestCase classes from this to setup and tearDown a SQLite-backed
MagicalRecord core data stack on each test.
The SQLite file itself will be deleted between runs.
@benvium
benvium / coreDataDebugging
Created June 1, 2015 20:35
Program arguments for Core Data SQLite debugging. In AppCode, edit your run configuration for your target, click the icon to the right of 'Program Arguments'. Paste in the following
-com.apple.CoreData.SQLiteIntegrityCheck
1
-com.apple.CoreData.ThreadingDebug
3
-com.apple.CoreData.SyntaxColoredLogging
1
-com.apple.CoreData.SQLDebug
1