在下面的代码中,我在"类型上有一个"实例成员;我尝试调用matchTravellerWithLocal
函数并将返回值分配给消息时出错。关于如何解决这个错误的任何想法?
var travellerInformation: Traveller{
return Traveller(destination: location, travellingPreference: preference)
}
let message = matchTravellerWithLocal(travellerInformation)
func matchTravellerWithLocal(traveller: Traveller) -> String {
var message = ""
let location = traveller.destination.rawValue
let type = traveller.travellingPreference.rawValue
let locals = LocalsInformation().locals
for (name, information) in locals{
let city = information["City"]
let preference = information["Preference"]
if city == location{
message = "Meet your local: \(name), a local of \(city)"
print(message)
}else{
message = "Apologies, there aren't in \(city) on LocalRetreat. Try again soon!"
break
}
if preference == type{
message += "who is also a \(preference)"
print(message)
}
}
return message
}