我是新来的。
我想找出如何以其他方式重用这个变量(项):
if var item = currentItem?.listCategoryScheme[countCategoryScheme].listCategory{
...
}
我试过这样做:
var item:NSObject?
func{
if item = currentItem?.listCategoryScheme[countCategoryScheme].listCategory{
...
}
} func2{
//here reuse item
}
但不起作用
谢谢
发布于 2014-10-13 01:49:20
声明您的变量如下:
var iteam : NSObject = NSObject()
在ViewController课堂上。
发布于 2014-10-13 01:47:39
var itemGlobal:String = String()
func printItem(item: String)
{
println(item)
itemGlobal = item
}
func printGlobalItem()
{
println(itemGlobal)
}
printItem("Swift") //prints "Swift" and assignes the itemGlobal to "Swift"
printGlobalItem() //prints "Swift", from the itemGlobal, previously assigned
https://stackoverflow.com/questions/26336884
复制