小编Sam*_*Sam的帖子

“NSLinguisticTag”类型的值没有成员“范围”

我有文本方向代码,它在 swift 3 中运行良好,但在迁移到 swift 4 后,我收到错误

let tagScheme = [NSLinguisticTagScheme.language]
    let tagger    = NSLinguisticTagger(tagSchemes: tagScheme, options: 0)
    tagger.string = self.text
    let lang      = tagger.tag(at: 0, scheme: NSLinguisticTagScheme.language,
                                      tokenRange: nil, sentenceRange: nil)

    if lang?.range(of: "he") != nil ||  lang?.range(of: "ar") != nil { //Value of type 'NSLinguisticTag' has no member 'range' 
        self.textAlignment = NSTextAlignment.right
    } else {
        self.textAlignment = NSTextAlignment.left
    }
Run Code Online (Sandbox Code Playgroud)

有人知道怎么修这个东西吗?谢谢

swift nslinguistictagger swift4

3
推荐指数
1
解决办法
496
查看次数

标签 统计

nslinguistictagger ×1

swift ×1

swift4 ×1