0

This my code

var changePhoto = [UIImage]()
let photoPng = UIImage(named: "1.png")
let photoJpg = UIImage(named: "1.jpg")

changePhoto += photoPng
changePhoto += photoJpg

but error "expected declaration"

Please help me! What's wrong?

3
  • Could you add a little more description about the problem you have? Commented Mar 27, 2015 at 7:03
  • error is expected declaration. No explain any more. ^^ Commented Mar 27, 2015 at 8:03
  • @rintaro Thanks lot. I think that exactly problem. Commented Mar 28, 2015 at 14:12

1 Answer 1

0

You need to use the append method to add new objects to your array:

changePhoto.append(photoPng)
changePhoto.append(photoJpg)

Also, you only can have functionality inside of methods. So try to call it inside a method. for example if you use a Viewcontroller in your viewDidLoad method.

Sign up to request clarification or add additional context in comments.

5 Comments

I already use that code. But it's not done. Same error. I'm using Xcode 6.3 beta 4. But in my opinion it's not issue.
Try changePhoto.append(photoPng!)
@MinhThắngTrương Check my update. Maybe you call it outside of a function. That's not allowed. You can only use functionality inside a method.
@Christian! Thanks! that's exactly excuse.
Glad it worked. If you accept the answer, other people can find it easier.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.