
我还得到另一个错误变量’numberOfGames’在被初始化之前在行上返回numberOfGames.
这是包含两个错误的函数:
func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int { var user: PFUser! var numberOfGames: Int //...query code....removed to make it easIEr to read var query = PFquery.orqueryWithSubquerIEs([userquery,userquery2,currentUserquery,currentUserquery2]) query.findobjectsInBackgrounDWithBlock{ (results: [AnyObject]?,error: NSError?) -> VoID in if error != nil { println(error) } if error == nil{ if results != nil{ println(results) numberOfGames = results!.count as Int } } } return numberOfGames } 您需要在使用它之前初始化变量: As per apple documentation
If you use a closure to initialize a property,remember that the rest
of the instance has not yet been initialized at the point that the
closure is executed. This means that you cannot access any other
property values from within your closure,even if those propertIEs
have default values. You also cannot use the implicit self property,
or call any of the instance’s methods.
命令var numberOfGames:Int只是声明它初始化你可以使用var numberOfGames = Int()或var numberOfGames:Int = 0
func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int { var user: PFUser! var numberOfGames:Int = 0 var query = PFquery.orqueryWithSubquerIEs([userquery,error: NSError?) -> VoID in if error != nil { println(error) } if error == nil{ if results != nil{ println(results) numberOfGames = results!.count as Int } } } return numberOfGames } 总结 以上是内存溢出为你收集整理的swift – 被初始化之前由闭包捕获的变量全部内容,希望文章能够帮你解决swift – 被初始化之前由闭包捕获的变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)