我正在使用下面的函数将新的 rtfd数据设置为核心数据实体中二进制类型的属性。
如果它不相等,那么我将数据设置为托管对象。
此处的问题是,仅当 rtfd数据仅为文本时,相等才有效。当附加图片时,此方法返回false。
-(BOOL)setRTFData:(NSData*)data forKey:(NSString*)key
{
NSData *actualData = [self getDataValueForKey:key];
NSDictionary *dict = nil;
NSAttributedString *actualAttribString = [[NSAttributedString alloc] initWithRTFD:actualData documentAttributes:&dict];
NSAttributedString *newAttribString = [[NSAttributedString alloc] initWithRTFD:data documentAttributes:&dict];
BOOL isEqual = [actualAttribString isEqualToAttributedString:newAttribString];
[actualAttribString release];
[newAttribString release];
if (!isEqual)
{
[self willChangeValueForKey:key];
[self setPrimitiveValue:data forKey:key];
[self didChangeValueForKey:key];
return TRUE;
}
return FALSE;
}
这就是我从NSTextView
获取* rtfd数据 *的方式:
NSData* data = [notesTextField RTFDFromRange:NSMakeRange(0,[[notesTextField textStorage] length])];
我正在使用sdk 10.7