0

I am following a tutorial called "Starting Developing iOS Apps (Swift)" at this link. https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson5.html#//apple_ref/doc/uid/TP40015214-CH19-SW1

I have followed the tutorial exactly, to the best of my knowledge, and am confused what the issue is with the last line of code in the following code block.

        var ratingButtons = [UIButton]()
        ...
        // MARK: Button Action
        func ratingButtonTapped(button: UIButton){
            //print("Button pressed ")
            rating = ratingButtons.indexOf(button)! + 1
        }

I am very new to iOS development and do not understand a few things here.

First, I get the error '[(UIButton)]' does not have a member named 'indexOf'. Is there significance to the brackets and parentheses surrounding UIButton? Also, to my understanding ratingButtons is an array so shouldn't indexOf work properly in this case?

killianjackson
  • 115
  • 1
  • 6

2 Answers2

3

indexOf was created as of Swift 2.0. YOU DON'T need to update your Xcode, just use the find method,

rating = find(ratingButtons, button)! + 1
z'''z
  • 51
  • 5
1

That tutorial is about Swift 2.0. indexOf exists in Swift 2.0. You are using Swift 1.2, so it doesn't exist for you. Update to Xcode 7 so you can use Swift 2.0.

matt
  • 515,959
  • 87
  • 875
  • 1,141