Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么我的实体对象不插入数据?_Iphone_Objective C_Cocoa Touch_Core Data - Fatal编程技术网

Iphone 为什么我的实体对象不插入数据?

Iphone 为什么我的实体对象不插入数据?,iphone,objective-c,cocoa-touch,core-data,Iphone,Objective C,Cocoa Touch,Core Data,这是我的情况。。我是Objective-C的新手,我正在尝试制作我的第一个核心数据样本,但我已经被困在这太多的时间里了。代码应该在my Points实体中插入一个名为“id”的属性。这是我的一段代码,我希望你们能帮我找出我遗漏了什么或做错了什么 地点 -(IBAction)insert_click:(id)sender{ NSNumber* x = [NSNumber numberWithInt: 10]; Msa_v3AppDelegate *

这是我的情况。。我是Objective-C的新手,我正在尝试制作我的第一个核心数据样本,但我已经被困在这太多的时间里了。代码应该在my Points实体中插入一个名为“id”的属性。这是我的一段代码,我希望你们能帮我找出我遗漏了什么或做错了什么

地点

-(IBAction)insert_click:(id)sender{                
    NSNumber* x = [NSNumber numberWithInt: 10]; 
    Msa_v3AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSManagedObjectContext *context = [appDelegate managedObjectContext];
    Points *p =(Points *) [NSEntityDescription insertNewObjectForEntityForName:@"Points" inManagedObjectContext:context];  
    [p setId:x];    

    NSError *error;     
    if(![managedObjectContext save:&error]){        
        //handle error      
    } 
} 
**location类是一个NSObject类

h点

@interface Points :  NSManagedObject  
{
}

@property (nonatomic, retain) NSNumber * id;

@end
点m

@implementation Points 

@dynamic id;

@end

代码编译正常,未发送任何错误或警告消息,但插入仍不起作用。。有什么线索吗?

最后我找到了这个问题的答案,我发现我的应用程序实际上是在插入数据,但我的获取方法是错误的,我正在初始化实体对象,如

    Points *p =(Points *) [NSEntityDescription insertNewObjectForEntityForName:@"Points" inManagedObjectContext:context];
而不是

    Points *p =(Points *) [NSEntityDescription EntityForName:@"Points" inManagedObjectContext:context];

你是如何得出插入不起作用的结论的?您必须正在获取实体。您可以显示执行提取的代码吗?您还可以使用SQLite viewer应用程序检查您的数据库,以确保是否插入了数据。感谢您的评论,我们意外插入数据的代码,问题出在我的提取方法中。