iOS iPhone - NSArray下一个获取对象&以前

时间:2014-02-18 19:27:13

标签: core-data nsarray

(
"<Songs: 0xa4f3510> (entity: Songs; id: 0xa4f2db0 <x-coredata://C569FCE5-9DE8-4421-AE91-7649ABB0276C/Songs/p1> ; data: {\n    name = \"Lil Wayne ft  Birdman Future Mack Maine Nicki Minaj - Tapout (CDQ NoShout) (2012)  www RnB4U in \";\n})",
"<Songs: 0xa4f0f70> (entity: Songs; id: 0xa4f2dc0 <x-coredata://C569FCE5-9DE8-4421-AE91-7649ABB0276C/Songs/p2> ; data: {\n    name = \"Matador (IE) - Svinx\";\n})",
"<Songs: 0x1c7e2470> (entity: Songs; id: 0xa499680 <x-coredata://C569FCE5-9DE8-4421-AE91-7649ABB0276C/Songs/p3> ; data: {\n    name = \"Cherno Feredje - Kaka Dora (heminei com)\";\n})"
)

如何仅获取name = .......... from array

以及如何在NSArray中进行搜索,如果我发现名称有下一个按钮,当我点击下一个时我想在数组中获得下一个名字?

2 个答案:

答案 0 :(得分:0)

要搜索NSArray,您需要在NSPredicate上使用-filteredArrayUsingPredicate:NSArray方法。

在这种情况下,如果您要搜索名称,可以使用以下代码进行编码:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", someNameValue];
NSArray *filtered = [myResultsArray filteredArrayUsingPredicate:predicate];

答案 1 :(得分:0)

如果您想要一个包含所有名称和所有歌曲的数组,可以使用NSArray *names = [resultsArray valueForKeyPath:@"@unionOfObjects.name"]

相关问题