Skip to content

Commit

Permalink
Replace checks for entityName on NSManagedObject subclasses with `n…
Browse files Browse the repository at this point in the history
…ameOfEntity`

`entityName` is declared on NSObject and was causing validation warnings when submitting to the App Stores.
  • Loading branch information
tonyarnold committed Apr 12, 2014
1 parent 316fd8e commit 723827e
Show file tree
Hide file tree
Showing 38 changed files with 56 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#import <CoreData/CoreData.h>
#import "MagicalRecord.h"
#import "MagicalRecordDeprecated.h"

#define kMagicalRecordDefaultBatchSize 20

Expand All @@ -17,7 +18,7 @@
*
* @return String based name for the entity
*/
+ (NSString *) MR_internalEntityName;
+ (NSString *) MR_nameOfEntity;

+ (NSUInteger) MR_defaultBatchSize;
+ (void) MR_setDefaultBatchSize:(NSUInteger)newBatchSize;
Expand Down Expand Up @@ -59,6 +60,7 @@

@interface NSManagedObject (MagicalRecordDeprecated)

+ (NSString *) MR_internalEntityName MR_DEPRECATED_WILL_BE_REMOVED_IN_3_0_USE("Please use +MR_nameOfEntity instead.");
+ (instancetype) MR_createInContext:(NSManagedObjectContext *)context __attribute__((deprecated("Please use +MR_createEntityInContext: instead.")));
- (BOOL) MR_deleteInContext:(NSManagedObjectContext *)context __attribute__((deprecated("Please use -MR_deleteEntityInContext: instead.")));

Expand All @@ -67,7 +69,9 @@
@protocol MagicalRecord_MOGenerator <NSObject>

@optional
+ (NSString *)nameOfEntity;
- (instancetype) entityInManagedObjectContext:(NSManagedObjectContext *)object;
- (instancetype) insertInManagedObjectContext:(NSManagedObjectContext *)object;

@end

Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@

@implementation NSManagedObject (MagicalRecord)

+ (NSString *) MR_internalEntityName;
+ (NSString *) MR_nameOfEntity;
{
NSString *entityName;
if ([self respondsToSelector:@selector(entityName)])
NSString *internalEntityName;

if ([self respondsToSelector:@selector(nameOfEntity)])
{
entityName = [self performSelector:@selector(entityName)];
internalEntityName = [self performSelector:@selector(nameOfEntity)];
}
if ([entityName length] == 0) {
entityName = NSStringFromClass(self);

if ([internalEntityName length] == 0) {
internalEntityName = NSStringFromClass(self);
}
return entityName;

return internalEntityName;
}

+ (void) MR_setDefaultBatchSize:(NSUInteger)newBatchSize
Expand Down Expand Up @@ -101,7 +101,7 @@ + (void) MR_performFetch:(NSFetchedResultsController *)controller

+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context
{
NSString *entityName = [self MR_internalEntityName];
NSString *entityName = [self MR_nameOfEntity];
return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}

Expand Down Expand Up @@ -302,6 +302,11 @@ - (id) MR_inThreadContext

@implementation NSManagedObject (MagicalRecordDeprecated)

+ (NSString *) MR_internalEntityName
{
return [self MR_nameOfEntity];
}

+ (instancetype) MR_createInContext:(NSManagedObjectContext *)context
{
return [self MR_createEntityInContext:context];
Expand Down
10 changes: 5 additions & 5 deletions Tests/Core/NSManagedObject+MagicalRecordTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ @implementation NSManagedObjectMagicalRecord

- (void)testThatInternalEntityNameReturnsClassNameWhenEntityNameMethodIsNotImplemented
{
expect([EntityWithoutEntityNameMethod MR_internalEntityName]).toNot.beNil();
expect([EntityWithoutEntityNameMethod MR_internalEntityName]).to.equal(NSStringFromClass([EntityWithoutEntityNameMethod class]));
expect([EntityWithoutEntityNameMethod MR_nameOfEntity]).toNot.beNil();
expect([EntityWithoutEntityNameMethod MR_nameOfEntity]).to.equal(NSStringFromClass([EntityWithoutEntityNameMethod class]));
}

- (void)testThatInternalEntityNameReturnsProvidedNameWhenEntityNameMethodIsImplemented
{
expect([EntityWithoutEntityNameMethod MR_internalEntityName]).toNot.beNil();
expect([DifferentClassNameMapping MR_internalEntityName]).toNot.equal(NSStringFromClass([DifferentClassNameMapping class]));
expect([DifferentClassNameMapping MR_internalEntityName]).to.equal([DifferentClassNameMapping entityName]);
expect([EntityWithoutEntityNameMethod MR_nameOfEntity]).toNot.beNil();
expect([DifferentClassNameMapping MR_nameOfEntity]).toNot.equal(NSStringFromClass([DifferentClassNameMapping class]));
expect([DifferentClassNameMapping MR_nameOfEntity]).to.equal([DifferentClassNameMapping nameOfEntity]);
}

@end
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/AbstractRelatedEntity.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "AbstractRelatedEntity.h"


@interface AbstractRelatedEntity ()

// Private interface goes here.

@end


@implementation AbstractRelatedEntity

// Custom logic goes here.
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/ConcreteRelatedEntity.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "ConcreteRelatedEntity.h"


@interface ConcreteRelatedEntity ()

// Private interface goes here.

@end


@implementation ConcreteRelatedEntity

// Custom logic goes here.
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/DifferentClassNameMapping.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "DifferentClassNameMapping.h"


@interface DifferentClassNameMapping ()

// Private interface goes here.

@end


@implementation DifferentClassNameMapping

// Custom logic goes here.
Expand Down
3 changes: 0 additions & 3 deletions Tests/Fixtures/TestModel/EntityWithoutEntityNameMethod.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//
// EntityWithoutEntityNameMethod.h
// MagicalRecord
//
// Created by Tony Arnold on 11/04/2014.
// Copyright (c) 2014 Magical Panda Software LLC. All rights reserved.
//
Expand Down
3 changes: 0 additions & 3 deletions Tests/Fixtures/TestModel/EntityWithoutEntityNameMethod.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//
// EntityWithoutEntityNameMethod.m
// MagicalRecord
//
// Created by Tony Arnold on 11/04/2014.
// Copyright (c) 2014 Magical Panda Software LLC. All rights reserved.
//
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/MappedEntity.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "MappedEntity.h"


@interface MappedEntity ()

// Private interface goes here.

@end


@implementation MappedEntity

// Custom logic goes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h"


@interface SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey ()

// Private interface goes here.

@end


@implementation SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey

// Custom logic goes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityRelatedToMappedEntityUsingDefaults.h"


@interface SingleEntityRelatedToMappedEntityUsingDefaults ()

// Private interface goes here.

@end


@implementation SingleEntityRelatedToMappedEntityUsingDefaults

// Custom logic goes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h"


@interface SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey ()

// Private interface goes here.

@end


@implementation SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey

// Custom logic goes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h"


@interface SingleEntityRelatedToMappedEntityWithNestedMappedAttributes ()

// Private interface goes here.

@end


@implementation SingleEntityRelatedToMappedEntityWithNestedMappedAttributes

// Custom logic goes here.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityRelatedToMappedEntityWithSecondaryMappings.h"


@interface SingleEntityRelatedToMappedEntityWithSecondaryMappings ()

// Private interface goes here.

@end


@implementation SingleEntityRelatedToMappedEntityWithSecondaryMappings

// Custom logic goes here.
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/SingleEntityWithNoRelationships.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleEntityWithNoRelationships.h"


@interface SingleEntityWithNoRelationships ()

// Private interface goes here.

@end


@implementation SingleEntityWithNoRelationships

// Custom logic goes here.
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/TestModel/SingleRelatedEntity.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#import "SingleRelatedEntity.h"


@interface SingleRelatedEntity ()

// Private interface goes here.

@end


@implementation SingleRelatedEntity

// Custom logic goes here.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_AbstractRelatedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern const struct AbstractRelatedEntityAttributes {

@interface _AbstractRelatedEntity : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (AbstractRelatedEntityID*)objectID;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_AbstractRelatedEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"AbstractRelatedEntity" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"AbstractRelatedEntity";
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_ConcreteRelatedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern const struct ConcreteRelatedEntityAttributes {

@interface _ConcreteRelatedEntity : AbstractRelatedEntity {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (ConcreteRelatedEntityID*)objectID;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_ConcreteRelatedEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"ConcreteRelatedEntity" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"ConcreteRelatedEntity";
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_DifferentClassNameMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@interface _DifferentClassNameMapping : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (DifferentClassNameMappingID*)objectID;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_DifferentClassNameMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"EntityWithDifferentClassName" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"EntityWithDifferentClassName";
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_MappedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern const struct MappedEntityUserInfo {

@interface _MappedEntity : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (MappedEntityID*)objectID;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/TestModel/_MappedEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"MappedEntity" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"MappedEntity";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern const struct SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey

@interface _SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKeyID*)objectID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern const struct SingleEntityRelatedToMappedEntityUsingDefaultsRelationships

@interface _SingleEntityRelatedToMappedEntityUsingDefaults : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (SingleEntityRelatedToMappedEntityUsingDefaultsID*)objectID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ {
return [NSEntityDescription insertNewObjectForEntityForName:@"SingleEntityRelatedToMappedEntityUsingDefaults" inManagedObjectContext:moc_];
}

+ (NSString*)entityName {
+ (NSString*)nameOfEntity {
return @"SingleEntityRelatedToMappedEntityUsingDefaults";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern const struct SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyRelati

@interface _SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey : NSManagedObject {}
+ (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_;
+ (NSString*)entityName;
+ (NSString*)nameOfEntity;
+ (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_;
- (SingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyID*)objectID;

Expand Down
Loading

0 comments on commit 723827e

Please sign in to comment.