gpt4 book ai didi

ios - 合并解析查询并添加到单独的数组

转载 作者:行者123 更新时间:2023-11-29 01:48:51 35 4
gpt4 key购买 nike

如何组合多个解析查询?我想从 parse.com 查询列 sclinksongTitle,然后将它们分别添加到自己的数组中。

还有如何在本地保存查询并调用它? IF else 声明或其他内容:

NSMutableArray *trackList = [[NSMutableArray alloc] init];
PFQuery *queryTracks = [PFQuery queryWithClassName:@"liveRadioPL"];
NSArray *objects = [queryTracks findObjects]; // Online PFQuery results
[PFObject pinAllInBackground:objects];

[queryTracks selectKeys:@[@"scLink"]];
[queryTracks findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
totalTracks = (int)objects.count;
NSLog(@"Successfully retrieved %lu Tracks.", (unsigned long)objects.count);
// Do something with the found objects
for (PFObject *object in objects) {

[trackList addObject:[NSString stringWithFormat:@"%@", [object objectForKey:@"scLink"]]];


}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

trackListArray = trackList;


NSMutableArray *trackTitles = [[NSMutableArray alloc] init];

PFQuery *queryTitles = [PFQuery queryWithClassName:@"liveRadioPL"];
NSArray *objectsTitle = [queryTitles findObjects]; // Online PFQuery results
[PFObject pinAllInBackground:objects];

[queryTracks selectKeys:@[@"songTitle"]];
[queryTracks findObjectsInBackgroundWithBlock:^(NSArray *objectsTitle, NSError *error) {
if (!error) {
// The find succeeded.
totalTitles = (int)objectsTitle.count;
NSLog(@"Successfully retrieved %lu Titles.", (unsigned long)objectsTitle.count);
// Do something with the found objects
for (PFObject *object in objects) {

[trackTitles addObject:[NSString stringWithFormat:@"%@", [object objectForKey:@"songTitle"]]];


}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];

最佳答案

我不确定您的逻辑是否真的有意义 - 当您只需要 1 个 API 请求时,您正在使用 4 个 API 请求。另外,雅各布是对的,您正在从后台线程填充数组,因此主线程会将其视为空。

我想我明白你想要做什么 - 试试这个

PFQuery *queryTracks = [PFQuery queryWithClassName:@"liveRadioPL"];
// use includeKey if slink and songTitle are pointers to other Parse classes
// from the context of your question you probably don't need to use includeKey
[queryTracks includeKey:"scLink"];
[queryTracks includeKey:"songTitle"];
NSArray *objects = [queryTracks findObjects];

NSMutableArray* scLinks = [[NSMutableArray alloc] init];
NSMutableArray* songTitles = [[NSMutableArray alloc] init];

for (PFObject* object in objects) {
[scLinks addObject:object[@"scLink"]];
[songTitles addObject:object[@"songTitles"]];
}

希望这对您有所帮助,祝您好运!

关于ios - 合并解析查询并添加到单独的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634099/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com