Here is my code in Swift for an iOS app.
class Test {
var name: String
var sname: String
init(name: String, sname: String) {
self.name = name
self.sname = sname
}
}
class ArrTest {
var arr = [Test]()
init() {
arr.append(Test(name: "test1", sname: "surname1"))
arr.append(Test(name: "test2", sname: "surname2"))
arr.append(Test(name: "test3", sname: "surname3"))
arr.append(Test(name: "test4", sname: "surname4"))
}
}
var x = ArrTest()
let obj = x.arr.filter { $0.name == "test1" }.first
println(obj?.sname)
I want to get the index and not the object of the first array object (in the array var). The "obj" x.arr.filter... returns the first object. I need the index of the correct object.