Q:

How to compare attributes of a NSAttributedString?

I'm filtering attributed text depending on certain attributes. Is there a way to compare if ([attrString.attributes isEqualToDictionary:myAttributes]) ?

A:

You can use -enumerateAttributesInRange:options:usingBlock:
Within the block, you can test whether the attributes of a run are exactly equal to your desired set of attributes using [attrs isEqualToDictionary:myAttributes]. Be warned: This will return NO if the run contains any attributes you weren't looking for.
If you only want to see whether the attributes in myAttributes are set (and compare their values), without rejecting other attributes, use [[attrs dictionaryWithValuesForKeys:[myAttributes allKeys]] isEqualToDictionary:myAttributes].

