Voyager Voyager - 1 year ago 87
Swift Question

Get Model Object as Array in Swift

I have a person model that contains more than object, how do i calling this model as array in another class?

If I declare like this, I can't get count for the array

let personArray = Person()

override func viewDidLoad() {
let count = personArray.count >> crash

I need to list the person in the Table View so i need to get personArray.count

Appreciate any help..


Answer Source

Referring to Apple's Documentation, Person Model should represents encapsulated data. If you want to set an array of persons, you should do this:

let personsArray = [Person]()

persons array should contains Person() objects. Now you can:

override func viewDidLoad() {
     let count = personsArray.count

Hope that helped.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download