gpt4 book ai didi

iphone - 从文件加载NSAttributedString

转载 作者:行者123 更新时间:2023-12-01 18:18:42 27 4
gpt4 key购买 nike

有没有一种方法可以在文件中包含某种格式的富文本,然后将文件加载到NSAttributedString中?我研究了将.rtf文件加载到NSAttributed字符串中:

NSString *filePathFooter = [[NSBundle mainBundle] pathForResource:kFooterFileName ofType:@"rtf"];

NSError *error = nil;
NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:[NSURL URLWithString:filePathFooter]
options:nil
documentAttributes:NULL
error:&error];

但这给我留下了:
Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn’t be completed. (Cocoa error 258.)"

有没有办法做到这一点?

最佳答案

请改用URLForResource,然后像这样传递结果URL:

NSURL *url = [[NSBundle mainBundle] URLForResource:kFooterFileName withExtension:@"rtf"];

NSError *error = nil;
NSAttributedString *string = [[NSAttributedString alloc] initWithFileURL:url
options:nil
documentAttributes:NULL
error:&error];

关于iphone - 从文件加载NSAttributedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19105356/

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