【发布时间】:2015-09-14 18:22:33
【问题描述】:
我正在尝试使用 Swift 将 Parse 中的字符串对象添加到数组中。添加对象后数组为空,因此显然没有添加任何内容。怎么了?
var cities = NSMutableArray()
func retrieveCities() {
let cityQuery:PFQuery = PFQuery(className: "Locations")
cityQuery.limit = 1000
cityQuery.orderByAscending("City")
cityQuery.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
self.cities.addObject(object["City"] as! String)
}
}
NSLog("Cities: %@", self.cities)
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
self.loadingIndicator.stopAnimating()
}
} else {
}
}
}
这是我的 Objective-c 版本。
- (void)retrieveCities {
self.cities = [[NSMutableArray alloc]init];
PFQuery *cityQuery = [PFQuery queryWithClassName:@"Locations"];
[cityQuery setLimit:1000];
[cityQuery orderByAscending:@"City"];
[cityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (NSDictionary *objectDictionary in objects) {
[self.cities addObject:[objectDictionary objectForKey:@"City"]];
}
// Reload the table data and dismiss the loading indicator
dispatch_async(dispatch_get_main_queue(), ^ {
[self.tableView reloadData];
[self.loadingIndicator stopAnimating];
});
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
【问题讨论】:
-
我想知道查询是否真的返回任何东西或只是一个空数组。
标签: ios swift parse-platform pfquery