Cocoa: Testing to find if an NSString is immutable or mutable?

后端 未结 3 1825
伪装坚强ぢ
伪装坚强ぢ 2020-12-18 03:26

This produces an immutable string object:

NSString* myStringA = @\"A\";  //CORRECTED FROM: NSMutableString* myStringA = @\"A\";

This produc

3条回答
  •  伪装坚强ぢ
    2020-12-18 04:14

    There's no (documented) way to determine if a string is mutable at runtime or not.

    You would expect one of the following would work, but none of them work:

    [[s class] isKindOfClass:[NSMutableString class]]; // always returns false
    [s isMemberOfClass:[NSMutableString class]]; // always returns false
    [s respondsToSelector:@selector(appendString)]; // always returns true
    

    More info here, although it doesn't help you with the problem:

    http://www.cocoabuilder.com/archive/cocoa/111173-mutability.html

提交回复
热议问题