Ios NSAttributeString initWithData:选项:文档属性:错误:文档属性未保留在ARC中

Ios NSAttributeString initWithData:选项:文档属性:错误:文档属性未保留在ARC中,ios,nsattributedstring,Ios,Nsattributedstring,我正在尝试从NSData加载文档(它来自我应用程序中的Dropbox文件,但为了简单起见,下面的示例使用了一个.txt文件,这导致了我试图修复的相同问题) 问题: 我实例化了一个NSDictionary,并将其作为out参数传递给[nsAttributeString-initWithData:options:documentAttributes:error: 但是,NSDictionary实例被解除分配,并导致-initWithData:options:documentAttributes:er

我正在尝试从
NSData
加载文档(它来自我应用程序中的
Dropbox
文件,但为了简单起见,下面的示例使用了一个.txt文件,这导致了我试图修复的相同问题)

问题: 我实例化了一个NSDictionary,并将其作为out参数传递给
[nsAttributeString-initWithData:options:documentAttributes:error:

但是,NSDictionary实例被解除分配,并导致-initWithData:options:documentAttributes:error:崩溃

当我启用
NSZombie
时,我得到的错误是:[\uu-nsyi-retain]:发送到解除分配实例的消息

-
initWithData:options:documentAttribute:error:
将NULL传递给documentAttribute时运行正常

代码如下:

NSError* error;
NSString* path = [[NSBundle mainBundle] pathForResource:@"Forward Thinking"
                                                 ofType:@"txt"];
NSData* data = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedAlways error:&error];
if (data) {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSDictionary* documentAttributes = [[NSDictionary alloc] init];
        NSAttributedString* attrStr = [[NSAttributedString alloc] initWithData:data options:nil documentAttributes:&documentAttributes error:NULL];
        self.textView.attributedText = attrStr;
    });
}

任何线索都很好

您不应将传递给此方法的
NSDictionary
分配给该方法。你想要的是:

NSDictionary* documentAttributes;
NSAttributedString* attrStr = [[NSAttributedString alloc] initWithData:data options:nil documentAttributes:&documentAttributes error:NULL];
它正在向您传递
文档属性。您不会将属性传递给它