Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect if the NSString contains the NSTextAttachment image?

How can I detect if the NSString contains the NSTextAttachment [OBJ] shown on the picture below?

Logging the text doesn't show anything besides plain text.

NSLog(@" Message: %@", message);

I managed to delete it with:

NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"] invertedSet];
NSString *resultString = [[conversation.lastMessage componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];

but it feels more like a hack than real solution. I am really surprised that it's even showing up since the message is an instance of the NSString class...

enter image description here

like image 246
Janusz Chudzynski Avatar asked Dec 03 '25 08:12

Janusz Chudzynski


1 Answers

A text attachment is always associated with an NSAttachmentCharacter in the text. It is unprintable which is why you don't see it in the log. But you can search on it and delete it.

like image 141
matt Avatar answered Dec 05 '25 23:12

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!