1

enter image description hereI'm working on Stanford's Matchismo game and I'm trying to create an array of buttons that I can reference in the controller. it's a card game, each card a button.

I drag/drop a UIButton to the controller and then set it up in an outlet collection. Not only does it set it up but lets me link multiple outlets to that collection. So far so good.

However when I compile my code (target iOS 7.1) I get a 254 error. I've identified that it's the outlet collection that causes the error.

class MainController: UIViewController{

    let cardDeck = PlayingCardDeck()

    @IBOutlet var cardButtons: UIButton[]

}

When I replace the UIButton[] mention with NSArray the compiler loads without error. But this is not at all what the exercise is all about - I'm expecting Swift to register the outlets that have been linked to the UIButton[] array and allow me to manipulate that array.

That is, as far as I can tell, the expectation set by the "link to outlet collection" feature in XCode6 Beta 3.

I uploaded a screenshot of the error report. Apparently this has to do with unwrapping the weakly referenced optional array. This is beyond my powers to fix on my own.

Laurent
  • 1,554
  • 19
  • 42

2 Answers2

2

You need to define it properly, currently your declaration is not proper -

If you are defining outlet of array of buttons then use -

@IBOutlet var cardButtons: Array <UIButton>

If you are defining outlet of single button then use -

@IBOutlet var cardButton: UIButton

This is still not working in Xcode seed 6.3, however for possible workaround check this link - link

Community
  • 1
  • 1
rishi
  • 11,779
  • 4
  • 40
  • 59
  • It's the mention of UIButton in the line that causes the 254 error. In addition in Swift I understand that UIButton[] and [UIButton] are proper array declarations. – Laurent Jul 14 '14 at 05:56
  • yes, not working yet in Xcode 6.3, wait for next release. However there are workaround available if you wanted.. – rishi Jul 14 '14 at 06:33
  • Check this [link](http://stackoverflow.com/questions/24052459/swift-iboutletcollection-equivalent) – rishi Jul 14 '14 at 07:12
0

Try This

@IBOutlet var cardButtons: Array<UIButton>
Kathiravan G
  • 487
  • 4
  • 11