I have created a protocol as below
protocol FullyNamed {
var fullName: String { get }
}
Below my class which confirm this protocol
class Starship: FullyNamed {
var prefix: String?
var name: String
init(name: String, prefix: String? = nil) {
self.name = name
self.prefix = prefix
}
var fullName: String {
return (prefix != nil ? prefix! + " " : "") + name
}
}
var ncc1701 = Starship(name: "Enterprise", prefix: "USS")
// ncc1701.fullName is "USS Enterprise"
I realiaze that we use protcol as a listners when we use function in them Now when i add property here so why i will ever use a property in a protcol.Please answer
EDIT: As reading in the This link so is it just developer don't make mistake & must include confirm protocol because those objects will definitely have a 'name' ?