我在Swift中创建了一个结构,其中包含一个由类生成的全名列表:
class nameDetails {
var fullName: String
init(fullName: String) {
self.fullName = fullName
}
}
struct nameList {
let theList = [
nameDetails(fullName: "Bob Smith"),
nameDetails(fullName: "John Doe"),
nameDetails(fullName: "Sarah Taylor"),
nameDetails(fullName: "Gene Black"),
nameDetails(fullName: "Harry Snoden"),
nameDetails(fullName: "Lucy Lu"),
nameDetails(fullName: "Greg Smith")
]
func getRandomName() {
var sizeOfList = theList.count
var randomNumber = Int(arc4random_uniform(UInt32(sizeOfList)))
return theList[randomNumber]
}
}
我尝试使用该方法返回列表中的随机项。但是回归'声明声明以下错误: ' nameDetails'不能转换为'()'
有人可以指出我正确的方向吗?
谢谢。
答案 0 :(得分:0)
您必须指定func getRandomeName()
应为func getRandomName()->nameList