I'm pretty new in Swift so i'm asking here not why it doesn't work but why it does. I expected something different. I have three class, one called User.swift with User variables, get methods and constructor, another called UserList.swift with an array and a custom method to add objects to it and another in which simply i use this method to add User to this array.
As you can see, when i call listManager.addUser(...) i expected to write between parenthesis something like this: name: "random name", surname: "random surname", age: 0 but this give me a compilation error saying "Extraneous argument label 'name:' in call". If i delete "name:" it works, but if i delete "surname:" or "age:" it doesn't.
I'll put here my code (it works as i said, i have only to understand why).
User.swift
import Foundation
class User: NSObject {
private var name: String
private var surname: String
private var age: Int
init(name: String, surname: String, age: Int){
self.name = name
self.surname = surname
self.age = age;
}
func getName() -> String{
return self.name
}
func getSurname() -> String{
return self.surname
}
func getAge() -> Int{
return self.age
}
}
UserList.swift
import UIKit
var listManager: UserList = UserList()
class UserList: NSObject {
var userList = [User]()
func addUser(name: String, surname: String, age: Int){
userList.append(User(name: name, surname: surname, age: age))
}
}
Class in which i use addUser()
listManager.addUser("random name", surname: "random surname", age: 0)
As you can see there isn't "name:" label