首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法更改匿名块中的实例变量(Swift/Parse.com)

无法更改匿名块中的实例变量(Swift/Parse.com)
EN

Stack Overflow用户
提问于 2016-01-18 03:11:51
回答 2查看 68关注 0票数 1

解析数据是一个PFObject类,包含我正在查询的“公司”数据。获取数据并将其赋值为ParseData对象很好,但问题是将其放入我的listivar中。正如您从输出中看到的那样,匿名块中的ivars没有任何变化。有解决办法或解决方案吗?

代码语言:javascript
运行
复制
import Foundation
class AllCompanies: NSObject {
    var list:[ParseData] = []
    var testList:[String] = []
    var testString:String = "butter"

    override init()
    {
        super.init()
        getCompanies()
    }

    func getCompanies()
    {
        let query = ParseData.query()!
        query.findObjectsInBackgroundWithBlock { objects, error in
            if error == nil
            {
                for company in objects!
                {
                    let newCompany:ParseData = ParseData()
                    newCompany.name = company.objectForKey("Name") as! String
                    newCompany.logo = company.objectForKey("Logo") as! PFFile

                    self.list.append(newCompany)
                    self.testList.append("here")
                    self.testString = "no matter"
                }
            }
            else
            {
                print("Error: \(error) \(error?.userInfo)")
            }
        }
    }
}

方法调用:

代码语言:javascript
运行
复制
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("m0zIvk7nfP6nEUrGYzyecbhRdqTrhbUoBI00fvZ4", clientKey: "lmqPfyrkeq4p8v6cukV7aFCVdi4evb8MFyjgvnEG")
        PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
        let allCompanies = AllCompanies()
        print("\(allCompanies.list)")
        print("\(allCompanies.testList)")
        print("\(allCompanies.testString)")
        return true
}
EN

Stack Overflow用户

回答已采纳

发布于 2016-01-18 03:23:38

getCompanies方法是异步的吗?确保在运行print命令之前,findObjectsInBackgroundWithBlock method.You不能将异步代码编写为同步代码。试着在self.testString = "no matter".good运气下面写你的打印代码!

票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34846739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档