ios - 按数字排序解析对象
<p><p>我在 Parse 数据库中有一些对象,如下所示。我想按存储为数字的 highScore 对这些对象进行排序。
(</p>
<pre><code>"<Score: 0x7fee53740700, objectId: zMjL3eNWpI, localId: (null)> {\n Score = \"High Score: 60\";\n TeamName = \"Team0\";\n highScore = 60;\n}",
"<Score: 0x7fee534b5080, objectId: nysaJjYsth, localId: (null)> {\n Score = \"High Score: 86\";\n TeamName = Team1;\n highScore = 86;\n}",
"<Score: 0x7fee535f6ad0, objectId: 7Hj8RP4wYD, localId: (null)> {\n Score = \"High Score: 23\";\n TeamName = Team2;\n highScore = 23;\n}"
</code></pre>
<p>)</p>
<p>我有以下代码循环遍历对象并为每个对象提取 Number highScore,但我不确定如何继续。有没有办法可以返回(NSComparisonResult)NSOrderedAscending?如果有人有任何建议,请告诉我。谢谢。</p>
<pre><code>PFQuery *query = ;//class name is Score
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (int i = 0; i<=objects.count; i++){
NSArray *array = ;//Selects the first "object" from all the "objects"
NSNumber *test= ;
array = ;
test = ;
test1 = ;//test1 is the current database object highScore for the current object
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, );
}
}];
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>Parse.com 提供了一个很棒的 iOS SDK,它已经为您提供了开箱即用的功能。当您创建 <code>PFQuery</code> 时,Parse 为您提供了按您希望的方式对结果进行排序的选项。我相信你应该试试这个:</p>
<pre><code>PFQuery *query = ;
;
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
NSLog(@"High Score is %d", intValue]);
}
} else {
NSLog(@"Error: %@ %@", error, );
}
}];
</code></pre></p>
<p style="font-size: 20px;">关于ios - 按数字排序解析对象,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31763036/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31763036/
</a>
</p>
页:
[1]