使用Swift而不是Objective-C来保存Parse数据中的对象

时间:2015-09-05 16:17:35

标签: swift parse-platform uiviewcontroller

我正在将我的ViewController Objective-C转换为Swift

我想知道 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;

更新: 我在下面尝试了Lamar的答案,但是在findObjectsInBackgroundWithBlock行上出现了错误:'([AnyObject]!, NSError!) -> Void' is not compatible to 'PFArrayResultBlock?

enter image description here 以下是具体细节: enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个:

static shared_ptr<Layer<Dtype> > CreateLayer(const LayerParameter& param)
     {
    if (Caffe::root_solver()) {
      LOG(INFO) << "Creating layer " << param.name();
    }
    const string& type = param.type();
    CreatorRegistry& registry = Registry();
    CHECK_EQ(registry.count(type), 1) << "Unknown layer type: " << type
        << " (known types: " << LayerTypeListString() << ")";
    return registry[type](param);
  }