Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays SWIFT:创建使用类返回数组中随机项的结构方法时遇到错误_Arrays_Swift_Class_Methods - Fatal编程技术网

Arrays 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

我在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]
    }

}
我正在尝试使用该方法返回列表中的随机项。但“return”语句说明了以下错误: “nameDetails”不能转换为“()”

有人能给我指一下正确的方向吗


谢谢。

您必须指定
func getRandomeName()的返回类型。

它应该是
func getRandomName()->nameList