Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke 'init' with argument list of type StringLiteralConvertible

Tags:

xcode

ios

swift

when I try to run the code below I get this error:

Cannot invoke 'init' with argument list of type (id:StringLiteralConvertible,host:Contact,target:Contact,text:StringLiteralConvertible)

I tried using NSString and String in my class but still having the same problem. Can anyone guide me what i'm missing here?

class Contact {
    let id:String? = ""
    let name:String? = ""
    var number:String? = ""
    var photoPath:String? = ""
    var onlineStatus:Bool? = false

    init(id:String,name:String) {
        self.id = id
        self.name = name
        self.number = ""
        self.photoPath = ""
        self.onlineStatus? = false
    }
}

class Message {
    var id:String?
    var time:NSDate?
    var host:Contact?
    var target:Contact?

    init(id:String,host:Contact,target:Contact,time:NSDate) {
        self.id = id
        self.host = host
        self.target = target
        self.time = time
    }
}

class TextMessage:Message {
    var text:String?

    init(id: String, host: Contact, target: Contact, time: NSDate, text: String) {
        super.init(id: id, host: host, target: target, time: time)
        self.text = text
    }
}

let host = Contact(id: "", name: "")
let target = Contact(id: "", name: "")
let msg = TextMessage(id: "", host: host, target: target, time: NSData(), text: "")
like image 800
4aRk Kn1gh7 Avatar asked Jan 06 '15 05:01

4aRk Kn1gh7


1 Answers

You've got the wrong data type in your call to TextMessage init, should be NSDate()

let msg = TextMessage(id: "", host: host, target: target, time: NSDate(), text: "")
like image 88
applejack42 Avatar answered Sep 21 '22 05:09

applejack42