【发布时间】:2015-02-16 08:57:06
【问题描述】:
[self.managedObjectContext deletedObjects:lastPoint]; 这一行向我显示了一个错误
“NSManagedObjectContext”没有可见的@interface 声明选择器“deletedObjects”。
这是我的代码 谁能解决这个问题?
Appdelegate.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/* crete the fetch request first*/
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]initWithEntityName:@"Rectangle"];
NSError *requestError = nil;
/*And execute the fetch request on the context*/
NSArray *rectangle = [self.managedObjectContext executeFetchRequest:fetchRequest error:&requestError];
/*make sure we get the array*/
if ([rectangle count] > 0) {
/*delete the last person in the array*/
Rectangle *lastPoint = [rectangle lastObject];
[self.managedObjectContext deletedObjects:lastPoint];
if ([lastPoint isDeleted]) {
NSLog(@"Successfully deleted the last point...");
NSError *savingError = nil;
if ([self.managedObjectContext save:&savingError]) {
NSLog(@"successfully saved the context");
} else {
NSLog(@"Failed to save the context");
}
} else {
NSLog(@"Failed to delete the last point");
}
} else {
NSLog(@"Could not find any rectangle entities in the context.");
}
return YES;
}
【问题讨论】:
-
问题解决了吗?
-
你能解决这个问题吗? @Bhargav?
-
是的,我通过修改 Appdelegate.m
[self.managedObjectContext deleteObject:lastPoint];中的行来解决这个问题 -
@Bhargav 请在后面解释。我面临同样的错误stackoverflow.com/questions/33365748/…