ios - 在 CoreData 表中插入 50 个对象
<p><p>我想在 coredata ta 中插入 50 个值</p>
<pre><code> Question.h
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Question : NSManagedObject
@property (nonatomic, retain) NSString * question;
@property (nonatomic, retain) NSString * answer;
@property (nonatomic, retain) NSString * mcqsa;
@property (nonatomic, retain) NSString * mcqsb;
@property (nonatomic, retain) NSString * mcqsc;
@property (nonatomic, retain) NSString * mcqsd;
Question.m
#import "Question.h"
@implementation Question
@dynamic question;
@dynamic answer;
@dynamic mcqsa;
@dynamic mcqsb;
@dynamic mcqsc;
@dynamic mcqsd;
@end
</code></pre>
<p>插入代码</p>
<pre><code> - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSManagedObjectContext *context = ;
Question *question = [NSEntityDescription
insertNewObjectForEntityForName:@"Question"
inManagedObjectContext:context];
question.question = @"What is capital of Australia?";
question.answer = @"Testville";
question.mcqsa = @"Sydney";
question.mcqsb = @"Canbera";
question.mcqsc =@"Berlin";
question.mcqsd = @"Bern";
NSError *error;
if (!) {
NSLog(@"Whoops, couldn't save: %@", );
}
.......
</code></pre>
<p>如何插入多个数据,50 个问题及其 mcqs(50 个问题对象)?
有没有使用其他东西的手动方式?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p> <a href="https://github.com/magicalpanda/MagicalRecord" rel="noreferrer noopener nofollow">MagicalRecord</a> CoreData 的包装器提供了一些不错的导入功能。您需要在包中包含需要作为 plist/json 导入的数据。 </p>
<p>在初始运行时,您将数据导入 coreData。 </p>
<p>您可以在下面的链接<a href="http://www.cimgf.com/2012/05/29/importing-data-made-easy/" rel="noreferrer noopener nofollow">Importing data made easy</a> 中找到一个很好的教程。 </p>
<p>你需要创建 NSManagedObject 的子类</p>
<p>您可以在它们上调用 <code>importFromObject:</code> 或 <code>importFromObject:</code>。如果您对数据的结构有完全的控制权,这将发生在开箱即用的情况下,而无需编写用于将存储的数据映射到核心数据实体的单个代码。 </p></p>
<p style="font-size: 20px;">关于ios - 在 CoreData 表中插入 50 个对象,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16917828/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16917828/
</a>
</p>
页:
[1]