Alican Yilmaz Alican Yilmaz - 4 months ago 5x
Swift Question

Swift: Accessing members of tuples in Array

Why am i getting this error?
Error: Value of type 'Any' (aka protocol<>) has no member 'name'

import UIKit
var alican = (name: "alican", surame:"yilmaz")
var array:[Any] = [alican]


You've declared your Array as containing Any type. If you declare it like this the error should go away:

var array:[(name: String, surame: String)] = [alican]

If the array needs to be able to contain Any type you can pull out just those matching a particular type using flatMap.

var array:[Any] = [alican]
var nameSurnames = array.flatMap({ return $0 as? (name: String, surame: String) })