Swift:unwrapping导致swift编译缓慢 [英] Swift: unwrapping cause swift compile slowly
问题描述
在 func tableView(tableView:UITableView!,cellForRowAtIndexPath indexPath:NSIndexPath!) - > UITableViewCell!{
这行代码使swift编译速度极慢:
this line of code makes swift compile extremely slow:
cell!.detailTextLabel.text = child.year! + " " + child.make! + " " + child.model!
如果我有这行代码,我需要1分44秒才能构建项目。并且有99%的时间它坚持编译Swift源文件。
如果我将此行更改为
It takes me 1 min and 44 secs to build the project if I have this line of code. And 99% of the time it stuck at "Compiling Swift source files". If I change this line to
cell!.detailTextLabel.text = " "//child.year! + " " + child.make! + " " + child.model!
构建项目只需要5或6秒。
我想知道为什么这行代码会导致如此多的时间编译。
It only take me 5 or 6 sec to build the project. I would like to know why this line of code will cause so much time compiling.
在我的Child模型中,它们被声明为:
In my Child model, they are declared as :
var name:String?
var year:String?
var make:String?
var model:String?
和init:
init(name:String!, ... ,year:String!, make:String!, model:String!, ...){
self.name = name
...
self.year = year
self.make = make
self.model = model
}
我构建一个孩子的部分:
The part I construct a child:
Child(name:cName,...,year:cYear,make:cMake, model:cModel,...)
推荐答案
是的,我在这个缓慢的编译问题上提交了一个错误报告(17585851),你应该这样做;苹果发送的用例越明确越好。我的慢代码是这种形式的几次出现:
Yes, I filed a bug report (17585851) on this slow compilation issue, and you should do the same; the more clear use cases Apple is sent, the better. My slow code was several occurrences of this form:
let title = obj.valueForProperty(MPMediaItemPropertyTitle) as? String
self.titles += title ? title! : ""
(正如您所看到的,正在进行零测试/解包)。对我来说,通过以不同的方式做同样的事情来解决问题并不困难,但你也应该这样做。但首先提交bug报告!
(which, as you can see, is doing nil testing / unwrapping). It was cumbersome but not difficult for me to work around the problem by doing the same thing in a different way, and you should do likewise. But file that bug report first!
这篇关于Swift:unwrapping导致swift编译缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!