gpt4 book ai didi

swift - NSAttributedString has no member replacingOccurrences 错误

转载 作者:行者123 更新时间:2023-11-28 07:57:41 26 4
gpt4 key购买 nike

<分区>

这是我的代码

class AmDocViewController: UIViewController,UITextViewDelegate {
var text1:String!
let replaceYName: String = "text1"

var textA:String!
let replaceFName: String = "textA"

var textB:String!
let replaceyGFName: String = "textB"

@IBOutlet weak var myTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
myTextView.delegate = self;
self.view.endEditing(true)

let notes37 = NSAttributedString(string:"""
(SOME SAMPLE TEXT......)
""", attributes:[NSAttributedStringKey.foregroundColor: UIColor.gray])

let newMutableString77 = notes37.mutableCopy() as! NSMutableAttributedString
newMutableString77.append(notes37)

myTextView.attributedText = newMutableString77 as NSAttributedString

let originalString = myTextView.text

let updatedString = originalString?.replacingOccurrences(of: replaceYName, with: text1)
let updatedString1 = updatedString?.replacingOccurrences(of: replaceFName, with: textA)

if textB == "" {
let updatedString2 = updatedString1?.replacingOccurrences(of: str25, with: "N/A")
}
if textB != ""{
let updatedString2 = updatedString1?.replacingOccurrences(of: replaceyGFName, with: textB)
}

myTextView.text = updatedString2

myTextView.textAlignment = NSTextAlignment.center
}

在 if 语句行中获取以下错误消息

Argument type 'NSAttributedString' does not conform to expected type 'StringProtocol'

请建议如何使用从其他 ViewController TextField(text1) 接收的字符串值并替换 TextView 中的属性字符串?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com