Swift 更新全局变量
我在视图控制器中定义了一个全局变量。第二个函数需要使用第一个函数的产品。这些函数如何相互通信 var myPhotoArray:[UIImage]Swift 更新全局变量,swift,Swift,我在视图控制器中定义了一个全局变量。第二个函数需要使用第一个函数的产品。这些函数如何相互通信 var myPhotoArray:[UIImage] func loadImages() { for object in objects { let photoToView = object["imageFile"] as PFFile photoToView.getDataInBackgrou
func loadImages() {
for object in objects {
let photoToView = object["imageFile"] as PFFile
photoToView.getDataInBackgroundWithBlock({
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil){
var hereData = UIImage(data: imageData)
myPhotoArray.append(hereData!)
}
func numberOfImageView() {
if photoArray.count > 0 {
for i in 0...photoArray.count-1{
var widthPlace = CGFloat(i * 245)
var myImageView = UIImageView(frame: CGRectMake(widthPlace, 32, 245, 245))
myImageView.image = UIImage(named: "\(myPhotoArray[i])")
scroller.addSubview(myImageView)
} basically, second function needs to use the product of the first function .
最好的,你真的应该包含更多的代码。不管怎么说,从你的描述来看,我认为这个模型是可行的 如果一个变量是全局声明的(而不是在特定函数的范围内),那么两个函数都应该能够访问它
var arr = [1, 2]
func add() {
arr[1] = 2
}
func modify() {
arr[1] = 0
}
在这种情况下,第一个函数可以更新全局变量 好吧,这不是我要的。我在这里添加了更多代码。