'NSManagedObjectContext' 没有可见的@interface 声明
No visible @interface for 'NSManagedObjectContext' declares
[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;
}
因为the documentation说deletedObjects是只读的属性,所以它只有getter方法没有任何参数
所以你应该通过使用 next
来访问它
self.managedObjectContext.deletedObjects
错误信息
No visible @interface for 'NSManagedObjectContext' declares the
selector 'deletedObjects'.
告诉您 class NSManagedObjectContext
没有实现方法 deletedObjects
。您可以在 API documentation.
中查看
您可以使用deleteObject:
删除单个对象。因此,将您的代码更改为:
[self.managedObjectContext deleteObject:lastPoint];
[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;
}
因为the documentation说deletedObjects是只读的属性,所以它只有getter方法没有任何参数 所以你应该通过使用 next
来访问它self.managedObjectContext.deletedObjects
错误信息
No visible @interface for 'NSManagedObjectContext' declares the selector 'deletedObjects'.
告诉您 class NSManagedObjectContext
没有实现方法 deletedObjects
。您可以在 API documentation.
您可以使用deleteObject:
删除单个对象。因此,将您的代码更改为:
[self.managedObjectContext deleteObject:lastPoint];