I wanted to have a list or set which might contain two NSNumbers with the same integer value but it seems that memory is optimised so they are the same object.
e.g
NSNumber* n1=[NSNumber numberWithInt:10];
NSNumber* n2=[NSNumber numberWithInt:10];
then n1==n2;
Is there a way round this so that n1!=n2 ?
Not really. Cocoa keeps a cache of small numbers (IIRC those that represents integers from 0 to 12), and tagged pointers will also prevent that.
If you really need that, one option is to create a class that boxes
NSNumberinstances. In this way you can guarantee that different instances of your class will have different addresses.