objective c - iOS ReactiveCocoa RACObserve UITextView NSAttributedString -
i'm trying use reactivecocoa bindings bind uitextview's attributedtext model. however, attributedstring value not saved expected. wrong binding?
- (void)viewdidload { [super viewdidload]; nserror *error; nsattributedstring *attributedtext = [[nsattributedstring alloc] initwithdata:self.note.attributedtext options:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype, nscharacterencodingdocumentattribute: [nsnumber numberwithint:nsutf8stringencoding]} documentattributes:nil error:&error]; self.texttextview.attributedtext = attributedtext; rac(self.note, attributedtext) = [racobserve(self.texttextview, attributedtext) map:^id(nsattributedstring *attributedtext) { return [attributedtext datafromrange:nsmakerange(0, attributedtext.length) documentattributes:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype, nscharacterencodingdocumentattribute: [nsnumber numberwithint:nsutf8stringencoding]} error:nil]; }];
i believe can use rac_textsignal
category here. have tried following?
- (void)viewdidload { [super viewdidload]; nserror *error; nsattributedstring *attributedtext = [[nsattributedstring alloc] initwithdata:self.note.attributedtext options:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype, nscharacterencodingdocumentattribute: [nsnumber numberwithint:nsutf8stringencoding]} documentattributes:nil error:&error]; self.texttextview.attributedtext = attributedtext; @weakify(self); rac(self.note, attributedtext) = [self.texttextview.rac_textsignal map:^id(__unused nsstring *text) { @strongify(self); return [self.texttextview.attributedtext datafromrange:nsmakerange(0, attributedtext.length) documentattributes:@{nsdocumenttypedocumentattribute: nsrtfdtextdocumenttype, nscharacterencodingdocumentattribute: [nsnumber numberwithint:nsutf8stringencoding]} error:nil]; }]; }
Comments
Post a Comment