小编Rai*_*der的帖子

iOS:NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error 会导致哪些错误:

我正在使用 CoreData 构建一个 iOS 应用程序。我的一小部分用户(大约 1/1000)报告说应用程序在启动后不久就崩溃了。我怀疑持久存储协调器未能将数据库添加为持久存储。我一直无法在测试中重现任何错误,也无法从我的用户那里获得任何调试信息。有谁知道这种方法产生的任何常见错误?

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    if (persistentStoreCoordinator_ != nil) return persistentStoreCoordinator_;

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"databasefile.sqlite"];

    NSError *error = nil;

    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];

    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    return persistentStoreCoordinator_;
}
Run Code Online (Sandbox Code Playgroud)

core-data ios

5
推荐指数
1
解决办法
2480
查看次数

核心数据EXC_BAD_ACCESS用于非零整数值

我有两个具有int64_t属性的核心数据模型.当我尝试为整数字段分配非零值时,其中一个工作正常而另一个抛出EXC_BAD_ACCESS.我已经阅读了重新创建NSManagedObject子类的答案,但我没有成功.破碎的类看起来像这样:

@interface NoteObject : NSManagedObject

@property (nonatomic) int64_t remoteID;
@property (nonatomic) int64_t remoteArticleID;

@property (strong, nonatomic) ArticleObject *article;

@property (strong, nonatomic) NSString *status;
@property (strong, nonatomic) NSString *token;

@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *noteContent;

@property (strong, nonatomic) NSDate *pubDate;
@property (strong, nonatomic) NSDate *modDate;

@end

@implementation NoteObject

@dynamic remoteID;
@dynamic remoteArticleID;

@dynamic article;

@dynamic status;
@dynamic token;

@dynamic title;
@dynamic noteContent;

@dynamic pubDate;
@dynamic modDate;

@end
Run Code Online (Sandbox Code Playgroud)

违规行在此块中:

_noteObject = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:self.managedObjectContext];

_noteObject.remoteArticleID = 0; // …
Run Code Online (Sandbox Code Playgroud)

xcode core-data objective-c ios

4
推荐指数
1
解决办法
1347
查看次数

标签 统计

core-data ×2

ios ×2

objective-c ×1

xcode ×1