I'm trying to initialise an empty variable (of type a custom class) in Swift. Google has told me to use the 'lazy' keyword, but I'm getting the error "Missing argument for parameter 'name' in call":
lazy var currentEvent = Event()
Where an event is:
class Event {
let name: String
let venue: String
let description: String
let startTime: String
let coords: [Float]
let tags: [String]
let friendsAttending: Int
let imageURL: String
var seen: Bool
func setSeen(seen: Bool) {
self.seen = seen
}
init(name: String, venue: String, description: String, startTime: String, coords: [Float], tags: [String],
friendsAttending: Int, imageURL: String)
{
self.name = name
self.venue = venue
self.description = description
self.startTime = startTime
self.coords = coords
self.tags = tags
self.friendsAttending = friendsAttending
self.imageURL = imageURL
self.seen = false
GlobalVariables.imageCache.fetch(URL: NSURL(string: imageURL)!)
}
}
Am I using the keyword wrong (and how do I initialise an empty variable otherwise), or does my class need to implement something else to be lazy?
Aucun commentaire:
Enregistrer un commentaire