0
我正在將我的ViewController
從Objective-C轉換爲Swift。從使用Swift解析數據保存對象而不是Objective-C
我在想,如果findObjectsInBackgroundWithBlock
是仍然在使用(或者,如果將加載過慢)最聰明的事,如果我應該用同樣的方式。
我正在使用它獲取我的Parse
數據並將其保存到我的App Group
和/或NSUserDefaults
。
// Query Parse
PFQuery *query = [PFQuery queryWithClassName:@"data"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSMutableArray *localMatchup = [@[] mutableCopy];
for (PFObject *object in objects) {
// Add objects to local Arrays
[localMatchup addObject:[object objectForKey:@"matchup"]];
// App Group
NSString *container = @"group.com.ramsden.playoffs";
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:container];
// Matchup
[defaults setObject:localMatchup forKey:@"KeyMatchup"];
NSArray *savedMatchup = [defaults objectForKey:@"KeyMatchup"];
self.matchupArray = localMatchup;
更新: 我試過下面拉馬爾的答案,但我對findObjectsInBackgroundWithBlock行,說得到一個錯誤:'([AnyObject]!, NSError!) -> Void' is not compatible to 'PFArrayResultBlock?
H ey @Lamar,謝謝你的迴應!我認爲你在做什麼對我來說是有意義的,到目前爲止唯一的事情是,我在'findObjectsInBackgroundWithBlock'行中得到錯誤:'([AnyObject]!,NSError!) - > Void'不是兼容'PFArrayResultBlock?'。任何想法? – SRMR
替換我的代碼** query.findObjectsInBackgroundWithBlock {(對象:[AnyObject]?,錯誤:NSError?) - >無效** – Lamar
是的,這是有效的。對於你放置'//做任何你想做的事情'的部分,是否與我的代碼中有'// App Group'和'Matchup'的部分相對應? – SRMR