我想要一個字段添加到一個實體,每當我嘗試訪問新的領域,我得到與實體新的領域(無法識別的選擇錯誤)
無法識別的選擇發送到實例遇到問題.. 。
實體的其他一切工作。我能夠添加對象,我可以將值分配給對象中的其他字段,但不能分配給新對象。
值得注意的是,我還刪除了DerivedData
目錄,並刪除了.mom/.momd
文件以確保正確構建表。
有什麼想法?
Locations.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class Games, Players;
@interface Locations : NSManagedObject
@property (nonatomic, retain) NSNumber * defaultLoc;
@property (nonatomic, retain) NSString * locationAddr1;
@property (nonatomic, retain) NSString * locationAddr2;
@property (nonatomic, retain) NSString * locationCity;
@property (nonatomic, retain) NSNumber * locationID;
@property (nonatomic, retain) NSString * locationName;
@property (nonatomic, retain) NSString * locationState;
@property (nonatomic, retain) NSString * locationZip;
@property (nonatomic, retain) NSNumber * numberOfCourts;
@property (nonatomic, retain) NSNumber * defLoc;
@property (nonatomic, retain) NSSet *haveGames;
@property (nonatomic, retain) NSSet *havePlayers;
@end
@interface Locations (CoreDataGeneratedAccessors)
- (void)addHaveGamesObject:(Games *)value;
- (void)removeHaveGamesObject:(Games *)value;
- (void)addHaveGames:(NSSet *)values;
- (void)removeHaveGames:(NSSet *)values;
- (void)addHavePlayersObject:(Players *)value;
- (void)removeHavePlayersObject:(Players *)value;
- (void)addHavePlayers:(NSSet *)values;
- (void)removeHavePlayers:(NSSet *)values;
@end
Locations.m
#import "Locations.h"
#import "Games.h"
#import "Players.h"
@implementation Locations
@dynamic defaultLoc;
@dynamic locationAddr1;
@dynamic locationAddr2;
@dynamic locationCity;
@dynamic locationID;
@dynamic locationName;
@dynamic locationState;
@dynamic locationZip;
@dynamic numberOfCourts;
@dynamic defLoc;
@dynamic haveGames;
@dynamic havePlayers;
@end
注:defLoc和defaultLoc是我加了兩個字段。這些是給我的問題。
執行代碼:以上
- (IBAction)updateLocation:(UIStoryboardSegue *)segue
{
// If it is not "Edit" it is an "Add" and we need to insert a newobject.
if ([segueType1 isEqualToString:@"Add"])
{
NSManagedObjectContext *context = [[self fetchedResultsController] managedObjectContext];
location = [NSEntityDescription insertNewObjectForEntityForName:@"Locations" inManagedObjectContext:context];
}
location.locationName = lName;
location.locationAddr1 = lAddr1;
location.locationAddr2 = lAddr2;
location.locationCity = lCity;
location.locationState = lState;
location.locationZip = lZip;
location.numberOfCourts = lNumCourts;
location.defLoc = lNumCourts;
// location.defaultLoc = [NSNumber numberWithInt:1];
// DLog(@"ldefaultLocation = %@",ldefaultLocation);
location.defaultLoc = ldefaultLocation;
segueType1 = @"Add"; // Always reset back to Add so that segues work right
}
location.defLoc是給出了錯誤......所有其他位置的語句正常工作的命令。
您是否創建了新的Core Data模型版本?如果是的話,你是否將「當前版本」設置爲新版本? –
這似乎是正確的答案,因爲我之前沒有這樣做過。我做了關於如何實施,做了這個過程,嘗試刪除的東西,作爲一些建議......仍然沒有運氣:-(相同的消息 –