元素序列,但“join 不可用:调用 'joinWithSeparator()'";错误 [英] Sequence of elements, but "join is unavailable: call the 'joinWithSeparator()'" error

查看:33
本文介绍了元素序列,但“join 不可用:调用 'joinWithSeparator()'";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在操场上运行它时,为什么会在第 16 行(下面的最后一行)收到错误join isavailable: call the joinWithSeparator()"?而且,我该如何解决?

Why do I get the error "join is unavailable: call the joinWithSeparator()" at line 16 (the last line below) when I try to run it on playground? And, how can I fix it?

class Person {
    var firstName: String?
    var lastName: String?
    let gender = "female"

    func fullName() -> String {
        var parts: [String] = []

        if let firstName = self.firstName {
            parts += [firstName]
        }

        if let lastName = self.lastName {
            parts += [lastName]
        }
        return " ".join(parts)
    }
} 

推荐答案

错误消息告诉问题是什么,它告诉你如何解决它.阅读错误信息!执行错误消息所说的操作!

The error message tells you what the problem is, and it tells you how to fix it. Read the error message! Do what the error message says!

return parts.joinWithSeparator(" ")

这篇关于元素序列,但“join 不可用:调用 'joinWithSeparator()'";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆