ios - 如何从 coredata 实体中读取 NSArray
<p><p>我正在尝试将 coredata 实体读入 NSMutableArray,但是我不断收到大量奇怪的数据。例如,当我返回一个 NSDictionary 值时,它看起来像这样</p>
<pre><code>data: {
companyName = "WPremium";
desc = "Test";
guid = "Otq12342";
install = (
"0x1e59e910 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p851>",
"0x1e59e8e0 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p848>",
"0x1e59e830 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p837>",
"0x1e59e930 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p853>",
"0x1e59e850 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p839>",
"0x1e59e890 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p843>",
"0x1e59e8b0 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p845>",
"0x1e59e7c0 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p830>",
"0x1e5957e0 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p829>",
"0x1e59e810 <x-coredata://BAF7B1AD-F357-455A-B9D7-1288F7D1F652/Install/p835>",
"(...and 16 more...)"
);
</code></pre>
<p>我想知道如何将 coredata 字典的 install 对象放入一个 NSArray 中,以便对其进行排序。</p>
<p>更新:这就是我调用 coredata 对象的方式。</p>
<pre><code>- (NSMutableArray *)readSelectedInstall:(NSString *)projIDString {
NSManagedObjectContext *context = ;
if (context == nil) {
NSLog(@"Nil");
}
else {
NSFetchRequest *fetchRequest = [ init];
NSEntityDescription *entity = ;
;
NSPredicate *predicate = ;
;
NSError *error;
NSMutableArray *installProjectDictionaryArray = [ init];
NSArray *fetchedObjects = ;
for (InstallProject *installProj in fetchedObjects) {
NSMutableDictionary *tempInstallProjectDictionaryArray = [[ NSMutableDictionary alloc] init];
;
;
;
;
;
;
;
}
return installProjectDictionaryArray;
}
return nil;
}
</code></pre>
<p>然后使用返回的 NSMutableArray 我这样做</p>
<pre><code>NSMutableArray *getarray = ;
NSMutableDictionary *installsDictionary = ;
NSMutableArray *tempInstalls = ;
NSLog(@"%@", tempInstalls);
NSArray *tempSortedItemsArray = [tempInstalls sortedArrayUsingDescriptors:
@[[NSSortDescriptor
sortDescriptorWithKey:@"dp" ascending:YES],
[NSSortDescriptor
sortDescriptorWithKey:@"dc
" ascending:YES]]];
tempInstalls = ;
tempSortedItemsArray = nil;
NSLog(@"%@", tempInstalls);
</code></pre>
<p>但在最后一行代码中我有奇怪的输出。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要做的就是从 Core Data 中获取核心数据 NSManagedObject,install 将作为 NSSet 返回,看起来它是 NSManagedObjects 的 NSSet。 </p>
<p>获得对象后,您可以访问“安装”属性并根据需要进行排序。</p>
<pre><code>// Get the Core Data Object (Uses Magical Record)
MyObject *object = ];
// Sort the object set into an array
NSArray *installs = ]];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何从 coredata 实体中读取 NSArray,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19833681/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19833681/
</a>
</p>
页:
[1]