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

有帮助吗?

解决方案

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.

其他提示

NSLog calls the description selector on objects referenced by %@, so it prints strings even for objects which are not strings.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top