Arrays SWIFT:创建使用类返回数组中随机项的结构方法时遇到错误
我在Swift中创建了一个结构,其中包含一个类生成的全名列表:Arrays SWIFT:创建使用类返回数组中随机项的结构方法时遇到错误,arrays,swift,class,methods,Arrays,Swift,Class,Methods,我在Swift中创建了一个结构,其中包含一个类生成的全名列表: class nameDetails { var fullName: String init(fullName: String) { self.fullName = fullName } } struct nameList { let theList = [ nameDetails(fullName: "Bob Smith"), nameDeta
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]
}
}
我正在尝试使用该方法返回列表中的随机项。但“return”语句说明了以下错误:
“nameDetails”不能转换为“()”
有人能给我指一下正确的方向吗
谢谢。您必须指定
func getRandomeName()的返回类型。
它应该是func getRandomName()->nameList