gpt4 book ai didi

ios - NSAttributedString 到 NSData No visible @interface for 'NSAttributedString' 声明选择器 'RTFDFromRange :documentAttributes:

转载 作者:可可西里 更新时间:2023-11-01 03:28:26 60 4
gpt4 key购买 nike

我正在尝试使用 RTFDFromRange 方法将 NSAttributedString 转换为 NSData。得到这个:

No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes:

我的代码有什么问题?

NSAttributedString *val=self.textview.attributedText;
NSData *data = [val RTFDFromRange:NSMakeRange(0, self.textview.text.length) documentAttributes:nil];

最佳答案

NSAttributedString 没有用于 iOS 的名为 RTFDFromRange 的方法,但仅用于 Mac OS X。

要在iOS中将NSAttributedString转换为NSData,您可以尝试这两种方法:

1。使用 initWithData:

NSMutableAttributedString *val = [[NSMutableAttributedString alloc] initWithData:data options:nil documentAttributes:nil error:nil];

2。使用 NSKeyedArchiver:

NSData *data = [NSKeyedArchiver archivedDataWithRootObject: val];

然后将 NSData 转换回字符串:

NSAttributedString *val = [NSKeyedUnarchiver unarchiveObjectWithData: data];

此代码适用于 Mac 和 iOS。

请参阅 Apple 文档 here .

关于ios - NSAttributedString 到 NSData No visible @interface for 'NSAttributedString' 声明选择器 'RTFDFromRange :documentAttributes:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25134707/

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