Dmitriy Groschovskiy
Dmitriy Groschovskiy

Reputation: 153

Swift 3.0 NSArray valueForKey

In Swift 2.3 I've used this code, but after updating Swift to version 3.0 my code can't compile. Thank you!

var waterfallLibrary: NSArray = []
cell!.textLabel?.text = String(self.waterfallLibrary.valueForKey("songName").objectAtIndex(indexPath.row))

Upvotes: 3

Views: 5624

Answers (2)

Dmitriy Groschovskiy
Dmitriy Groschovskiy

Reputation: 153

My problem solved with this code

(waterfallLibrary.value(forKey: "songName") as! NSArray).object(at: indexPath.row)

Thank you Leo Dabus!

Upvotes: 9

Fogmeister
Fogmeister

Reputation: 77661

In swift 3.0 the first parameter name is required. So your code should be...

value(forKey: indexPath.row)

If you read the error message it will tell you this and it will even correct it for you.

If you want to convert all your code just use the built in xcode converter that will do all of this for you. Again, this will be offered when you open the project in Xcode 8.

Upvotes: 1

Related Questions