You can remove all attributes like this:
NSMutableAttributedString *originalMutableAttributedString =
Please note that set attributes are used for this (do not add ). From the docs:
These new attributes replace any attributes previously associated with characters in aRange .
If you need to do any of this conditionally, you can also list the attributes and delete them one at a time:
[originalMutableAttributedString enumerateAttributesInRange:originalRange options:kNilOptions usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop) { [attrs enumerateKeysAndObjectsUsingBlock:^(NSString *attribute, id obj, BOOL *stop) { [originalMutableAttributedString removeAttribute:attribute range:range]; }]; }];
In accordance with the documents, this is allowed:
If this method is sent to an NSMutableAttributedString instance, mutation is allowed (delete, add, or modify).
Swift 2
If string is a mutable string:
string.setAttributes([:], range: NSRange(0..<string.length))
And if you want to list for conditional deletion:
string.enumerateAttributesInRange(NSRange(0..<string.length), options: []) { (attributes, range, _) -> Void in for (attribute, object) in attributes { string.removeAttribute(attribute, range: range) } }