Giter Club home page Giter Club logo

magicalrecord's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicalrecord's Issues

iOS App Unit Test doesn't build.

Downloaded the source today. While trying to build the iOS App Unit Test it fails during build. Seems a file is missing. GHUnitIOSTestMain.m's path is:

../../../../../../saul/Desktop/iOS Test Frameworks/GHUnitIOSTestMain.m

Using MagicalRecord from a static lib (a la cocoapods)

Hi, and thanks for this great piece of software! I'm running into an issue, though, when using it from within a static lib:

I've used the podspec that you've submitted to cocoapods-specs to get MagicRecord integrated with my project. It builds into libpods.a and my code builds against it. At runtime I see:

2011-10-17 11:49:27.406 MyCode[85999:207] +[NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:]: unrecognized selector sent to class 0x1a4cfe4
2011-10-17 11:49:27.409 MyCode[85999:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:]: unrecognized selector sent to class 0x1a4cfe4'

I've tried the combinations of the -ObjC and -all_load flags in both the Pods project and my own, but the outcome is the same. Essentially, it looks like the category code in MR isn't being found.

Have you had success getting MR working with cocoapods, and if so, do you have a recipe for XCode 4.2?

Thanks very much!

Ability to specify location of a persistent store file

Currently, all stores are placed in the Library folder by default. In some cases, these stores may be user transferable at the least, and perhaps should be stored in the Documents folder when specified. All stores should still go to the Library by default.

Rejected from Mac App Store

  • (NSURL *) urlForStoreName:(NSString *)storeFileName gives a location that is disallowed.

Here is the message I received:

2.30

The application is creating files in, writing to, or opening for Read/Write access the following location:

"~/Library/CoreDataStore.sqlite"

#ifdef __IPHONE_5_0 does not work

Just running through your import tests for iOS 4.3 iPad/iPhone and the code block INSIDE of #ifdef __IPHONE_5_0 is getting executed. Not sure if this has something to do with the latest xcode beta or not ... but it will cause your A LOT of your tests to fail when running on anything < 5.0

-wg

NSInternalInconsistencyException

After setupCoreDataStackWithStoreNamed I make some findAll requests in my fist viewController. Efter terminating the application and I go back in again the same findAll request fire an exception. How can I make sure that the CoreData stack is set up properly when the application become active again.

Use CocoaLumberjack for Logging

It's my intent to convert the current logging to Cocoa Lumberjack. This may require a submodule.
Also, it's preferable to have the NSLogger connector so that log messages are displayed in NSLogger

question about leak in MagicalRecordHelpers.m

hello, I found this in your MagicalRecordHelper.m.
In dateFromString method, you allocate formatter object but not releasing.
So I change this line to
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];

Is't correct?

ARC Errors in 1.5

Hi, Im getting ARC Errors in +(void) cleanup

+ (void) cleanUp
{
[MRCoreDataAction cleanUp];
[NSManagedObjectContext setDefaultContext:nil];
[NSManagedObjectModel setDefaultManagedObjectModel:nil];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:nil];
[NSPersistentStore setDefaultPersistentStore:nil];
}

Automatic Reference Counting Issue: No known class method for selector 'setDefaultManagedObjectModel:'

Automatic Reference Counting Issue: No known class method for selector 'setDefaultPersistentStore:'

Is there something I haven't configured priorly?

Cheers Jonno

NSManagedObject+Proxy should be removed

That is the old "Clever" code - newer version is in NSManagedObject+ActiveRecord. I can fix that up quick if you want. Right now we have 2 categories on 'inContext:' so I'm not sure what XCode will do =/

Any preference if it is in +Proxy or +ActiveRecord?

deleteEntity on OSX

I have been using this code to delete an NSManagedContextObject. It works perfectly on all iOS environments.

MyObject *r = [_data objectAtIndex:row];
[ActiveRecordHelpers performSaveDataOperationWithBlock:^(NSManagedObjectContext *localContext){
    [r deleteEntity];
}];

For some reason, it doesn't work on OSX. In line 60 in ARCoreDataAction.m, in this method

+ (void) saveDataWithBlock:(void(^)(NSManagedObjectContext *localContext))block

The line

[localContext hasChanges]

return false. Even stranger, this code

[ActiveRecordHelpers performSaveDataOperationWithBlock:^(NSManagedObjectContext *localContext){
    [MyObject truncateAll];
}];

does modify the localContext and works exactly as expected (on OSX as well as iOS). Any ideas?

saveDataInBackgroundWithBlock when working in NSOperation

You emphasise main thread for saveDataInBackgroundWithBlock:^(NSManagedObjectContext *localContext) & certainly when calling it in an NSOperation its not working for me. So should I send each item of the data I'm processing to a selector in the main threat & call saveDataInBackgroundWithBlock there?

The code I'm running in my NSOperation is...

    [MRCoreDataAction saveDataInBackgroundWithBlock:^(NSManagedObjectContext *localContext){
        debug(@"genreObj: %@", [genreObj description]);
        Genre *localObj = [genreObj inContext:localContext];
        debug(@"localGenre: %@", [localObj description]);

        ... set localObj attributes ...
    }];

& the log for one instance of my objects is...

2011-10-04 00:07:32.245 myFestivals[51063:17b03] +[NSManagedObjectContext(MagicalRecord) contextWithStoreCoordinator:](0xf29d64) Creating MOContext genreObj: <Genre: 0x6035620> (entity: Genre; id: 0x6050000 <x-coredata:///Genre/tC5CB23CC-2B8B-4A3A-873B-73C08531BBE731> ; data: { eventprofiles = ( ); events = ( ); lastmoddate = 0; name = nil; smid = nil; }) 2011-10-04 00:07:32.256 myFestivals[51063:17b03] +[MagicalRecordHelpers defaultErrorHandler:](0x49470) Error Domain: NSCocoaErrorDomain 2011-10-04 00:07:32.279 myFestivals[51063:17b03] +[MagicalRecordHelpers defaultErrorHandler:](0x49470) Recovery Suggestion: (null) localGenre: (null)

While genreObj is a Core Data object localGenre remains null.

Cheers, Pedro :)

Block Syntax Error

saveWithErrorHandler:(void(^)(NSError *))error is missing a "()" around "^". You can pull this from my master

Why setIncludesSubentities:NO for request...sortedBy...withPredicate?

The class method

+ (NSFetchRequest *) requestAllSortedBy:(NSString *)sortTerm
                              ascending:(BOOL)ascending
                          withPredicate:(NSPredicate *)searchTerm
                              inContext:(NSManagedObjectContext *)context

(implemented in NSManagedObject+MagicalRecord.m) is the only method in the entire project that sends setIncludesSubentities:NO to the fetch request before returning. This means, for example, that

+ (NSArray *)findAllSortedBy:(NSString *)sortTerm
                   ascending:(BOOL)ascending
               withPredicate:(NSPredicate *)searchTerm
                   inContext:(NSManagedObjectContext *)context

won't return subentities.

I'm curious what prompted the setting of this property in this, and only this, case, as it seems rather odd. Why not take it out, so these methods are consistent with all the other ones?

Difference between createEntity and createInContext

Hello.
First of all - thanks for a great project, truly a great way to minimize the cruft of Core Data.
I'm evaluation MagicalRecord for my project, and have it working, but if I am using:
Book *b = [Book createEntity];
and not
Book *b = [Book createInContext:[NSManagedObjectContext defaultContext]];

Then, when calling 'save' - the 'hasChanges' method returns NO.

It's pretty obvious that I am missing something silly, and it's not a MagicalRecord bug, but the thing is - the sample snippets of code in the README are very nice, but a simple app that uses the library would really help out. Just something that shows:

  1. Initiating MagicalRecord with some store name
  2. Creating/Fetching entity
  3. Saving in background

Thanks in advance, and kudos for this great project!

Eli Yukelzon

feature idea: allow both strings and predicates

I've recently replaced my on version of MagicalRecords with yours, as its' more complete. One nice feature I had was all of my NSPredicate parameters were passed as "id", and could either be real predicates, as yours are, or a string, which made simple fetches even simpler. In case you are interested, here's the code...

// allows you to pass both predicates, and strings that we treat as predicates
if (stringOrPredicate) {
    NSPredicate *predicate = nil;
    if ([stringOrPredicate isKindOfClass:[NSString class]]) {
        predicate = [NSPredicate predicateWithFormat:stringOrPredicate];
    }
    else {
        NSAssert2([stringOrPredicate isKindOfClass:[NSPredicate class]],
                  @"Second parameter passed to %s is of unexpected class %@",
                  sel_getName(_cmd), NSStringFromClass([stringOrPredicate class]));
        predicate = (NSPredicate *)stringOrPredicate;
    }
    fetchRequest.predicate = predicate;
}

NSNotificationCenter observing NSManagedObjectContextObjectsDidChangeNotification doesn't work.

Having added MagicalRecord to a project which was built with plain vanilla Core Data. I've used this following pattern in a few places:

[[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextObjectsDidChangeNotification
                                                  object:[NSManagedObjectContext defaultContext]
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification *arg) {
    ...
}];

This never gets called. I see there's a context called contextThatNotifiesDefaultContextOnMainThread but that doesn't seem to work either.

PerformSelector may cause a leak because its selector is unknown

Getting this warning in the latest beta of XCode 4.2 in 3 spots:

[self performSelector:NSSelectorFromString(addRelatedObjectToSetMessage) withObject:relatedObject];
[mainContext performSelector:selector withObject:self];
[errorHandlerTarget performSelector:errorHandlerAction withObject:error];

Sample Code

Hello,
Although the sample snippets of code in the README are very nice - a simple app that uses the library would really help out. Just something that shows:

  1. Initiating MagicalRecord with some store name
  2. Creating/Fetching entity
  3. Saving in background

Thanks in advance, and kudos for this great project!

Eli Yukelzon

-setPropertiesToFetch: requires resultType == NSDictionaryResultType

-setPropertiesToFetch: is used in a few places in NSManagedObject+ActiveRecord.m, but the Xcode documentation for 'setPropertiesToFetch: notes:

This value is only used if resultType is set to NSDictionaryResultType.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSFetchRequest_Class/NSFetchRequest.html

I don't see where resultType is being set to NSDictionaryResultType. So, then, doesn't -setPropertiesToFetch: do nothing in these cases?

I may be missing something here... but I'm pretty sure I have my +'s & -'s straightened out this time. :)

Matt

Apple Mach-O Linker Error when building the source code

The error is: Duplicate symbol _ColorFromString.

The fix is to make sure ColorFromString in header file MagicalRecordHelpers.h is extern. Changing the declaration of ColorFromsString to the following will resolve the error.

extern id (*ColorFromString)(NSString *);

NSFetchedResultsController convenience methods should not call performFetch

Currently the NSFetchedResultsController methods (i.e. "fetchAllSortedBy") call performFetch before returning. However, this means you can't actually set a delegate (the arguably most common use case) or tweak the fetch request before executing your query. Yes, can just do the perform fetch again, but that doubles up the query time. Here's a typical use case that illustrates how I would like to call it...

    _fetchedResultsController = [[CTDiaryEntry fetchAllSortedBy:@"category,entryDate" ascending:YES withPredicate:predicate groupBy:@"category"] retain];
    _fetchedResultsController.fetchRequest.includesSubentities = YES;
    _fetchedResultsController.fetchRequest.includesPendingChanges = NO;
    _fetchedResultsController.delegate = self;

    [_fetchedResultsController performFetch:nil]

Since the helper returns a fetchedResultsController, rather than objects, it seems appropriate to simply construct the results controller and not to "act" on it. that's the caller's job.

NSManagedObjectContext resetDefaultContext hangs

While using NSManagedObjectContext's resetDefaultContext method, the dispatch never send the [[NSManagedObjectContext defaultContext] reset]; message.

It is importante to note that I am in a single thread application

"Error validating url for store"

Using latest pull I receive the error "Error validating url for store" after calling [ActiveRecordHelpers setupAutoMigratingCoreDataStack];

This occurred in an essentially new / empty project using Xcode 4.0.2 (4A2002a) using iOS 4.3 base SDK. Occurred on simulator and device (iPhone 4 GSM). Using a previous local version of MagicalRecord resolved the issue, with no changes in my applications code.

Add dynamic find methods

Like Rails' Active record, dynamic find methods should be created and attached to an NSManagedObject subclass to dynamically attach custom find methods. For example, a Person entity with a name attribute should have a dynamic method, or set of methods like:

Person.findByName(@"John Smith")

Rails has other variations on this that could be helpful, and valid

MRCoreDataAction cleanup_save_queue should NULL out background queue

MRCoreDataAction line 27:

void cleanup_save_queue()
{
if (coredata_background_save_queue != NULL)
{
dispatch_release(coredata_background_save_queue);
}
}

should read:

void cleanup_save_queue()
{
if (coredata_background_save_queue != NULL)
{
dispatch_release(coredata_background_save_queue);
coredata_background_save_queue = NULL;
}
}

otherwise after a call to cleanup, subsequent calls that use the background_save_queue() cause a crash.

Issue with repeated calls to findFirstByAttribute

Calling +findFirstByAttribute:@"example" withValue:@"something" with the same parameters multiple times results in a null response.

For example:
CDObject *test = [CDObject findFirstByAttribute:@"attribute" withValue:@"value1"
returns and object, later in the logic making the same call results in null

Changing the withValue parameter returns the expected object once but repeated calls to previously found objects results in null.

Fetch methods fail because entity name and class name are not always the same

I typically prefix my entity class names based on the project name in order not to pollute the flat namespace of Objective-C. So, for example, I have a little utility called CarGroupAssistant. It contains an entity name "Publisher" which is implemented by the entity class name "CGAPublisherEntity." Thus, when +entityDescriptionInContext is invoked, it fails to return a valid entity description instance.

One, of the top of my head, suggestion to solving this problem is to register a lookup to convert the class name to the entity name.

Problems with [request setFetchBatchSize:[self defaultBatchSize]];

I can't absolutely understand why, but this line in NSManagedObjectContext+ActiveRecord.m:
[request setFetchBatchSize:[self defaultBatchSize]];
makes my app crash on the first query.

I investigated and noticed that [self defaultBatchSize], when called for the first time, sets a static NSNumber to a default value of kActiveRecordDefaultBatchSize and this default value can't be changed, because both setDefaultBatchSize and defaultBatchSize are private members.

So I simply removed setDefaultBatchSize and defaultBatchSize methods and replaced the crashing line with:
[request setFetchBatchSize:kActiveRecordDefaultBatchSize];
and now it doesn't crash any more.

Create instance of NSFetchedResultsController?

The fetch request seems to be ok, and the rest of the viewcontroller is a stanfard tableview with nsfetched methods throughout

Can anyone give me a hand implementing this properly? It just crashes after returning the controller...
Cheers
Nik

'- (NSFetchedResultsController *)fetchedResultsController {

NSFetchRequest *fetchRequest = [Companies requestAllSortedBy:@"name" ascending:YES];

NSFetchedResultsController *aFetchedResultsController = [Companies fetchRequest:fetchRequest 
                                                                      groupedBy:nil];

aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;

[aFetchedResultsController release];
NSError *error = nil;
if (![fetchedResultsController_ performFetch:&error]) {

    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    abort();
}

return fetchedResultsController;

} '

Default Managed Object Context doc section totally confusing

The section titled "Default Managed Object Context" in the doc is totally confusing to me. It reads like the context method returns the default context, which I don't think is true.

It should be rewritten with the perspective of somebody who doesn't know the framework.

Thanks.

Failing to define MR_SHORTHAND breaks MagicalRecord

Just started fooling around with MagicalRecord, followed the instructions for adding it to my project. I got build failures until I set MR_SHORTHAND in my .pch

To reproduce:

  1. Create a new iOS project in XCode (4, if it matters)
  2. Add the MagicalRecord files to the project
  3. Add the CoreData+MagicalRecord.h header to the application .pch
  4. Compile, it should result in a build failure

The cause:
MagicalRecord scopes its category methods with MR_, which are aliased to their non-namespaced variant if MR_SHORTHAND is defined. MagicalRecordHelpers.m makes direct reference to the un-aliased method names, which causes the error.

deleteEntity on OSX

I have been using this code to delete an NSManagedObject. It works perfectly on all iOS environments.

MyObject *r = [_data objectAtIndex:row];
[ActiveRecordHelpers performSaveDataOperationWithBlock:^(NSManagedObjectContext *localContext){
    [r deleteEntity];
}];

For some reason, it doesn't work on OSX. In line 60 in ARCoreDataAction.m, in this method

+ (void) saveDataWithBlock:(void(^)(NSManagedObjectContext *localContext))block

The line

[localContext hasChanges]

return false. Even stranger, this code

[ActiveRecordHelpers performSaveDataOperationWithBlock:^(NSManagedObjectContext *localContext){
    [MyObject truncateAll];
}];

does modify the localContext and works exactly as expected (on OSX as well as iOS). Any ideas?

Cloud Syncing

It would be cool if Core Data could sync to the cloud. Just wondering if anyone else has worked on this and if this might be checked in in the near future -- or whether this type of feature doesn't belong in this repo.

Am I missing something? Save or Commit method

What is the correct way to save changes to an entity? There is no [newEntity commit];

Specifically, after creating a new entity and setting some attributes, when are these changes flushed to the persistent store?

performSaveDataOperationInBackgroundWithBlock possible bug

Hi Saul,

Thanks for sharing a great framework!
I consider to adopt your approach to manage Core Data stack and go over your code.

In MagicalRecordHelpers.m there is a method to save in background that reads as:

  • (void) performSaveDataOperationInBackgroundWithBlock:(CoreDataBlock)block;
    {
    [MRCoreDataAction saveDataWithBlock:block];
    }

Shouldn't it be [MRCoreDataAction saveDataInBackgroundWithBlock:block]; ???
Otherwise it looks a bit strange.

Thanks again,
Alex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.