NSAttributedString does not have a method called RTFDFromRange for iOS, but only for Mac OS X.
To convert NSAttributedString to NSData on iOS, you can try the following two approaches:
1. Using initWithData :
NSMutableAttributedString *val = [[NSMutableAttributedString alloc] initWithData:data options:nil documentAttributes:nil error:nil];
2. Using NSKeyedArchiver :
NSData *data = [NSKeyedArchiver archivedDataWithRootObject: val];
And to convert NSData back to string:
NSAttributedString *val = [NSKeyedUnarchiver unarchiveObjectWithData: data];
This code works on both Mac and iOS.
See Apple docs here .
source share