LoginSignup
1
0

More than 1 year has passed since last update.

NSStringにstringValueは無い

Last updated at Posted at 2015-08-05
NSLog(@"NSNumber.intValue    = %d", (@98765).intValue);
NSLog(@"NSString.intValue    = %d", @"01234".intValue);
NSLog(@"NSNumber.stringValue = %@", (@98765).stringValue);
NSLog(@"NSString.stringValue = %@", @"01234".stringValue);

こうすると、最後の行でエラーが出る。

Property 'stringValue' not found on object of type 'NSString *'

エラーが出るならいいけど、

NSDictionary *dic = @{ @"num": @98765, @"str": @"01234" };
NSLog(@"NSNumber.intValue    = %d", [dic[@"num"] intValue]);
NSLog(@"NSString.intValue    = %d", [dic[@"str"] intValue]);
NSLog(@"NSNumber.stringValue = %@", [dic[@"num"] stringValue]);
NSLog(@"NSString.stringValue = %@", [dic[@"str"] stringValue]);

なんてことをしていると、

NSNumber.intValue    = 98765
NSString.intValue    = 1234
NSNumber.stringValue = 98765
-[__NSCFConstantString stringValue]: unrecognized selector sent to instance 0xe65284
NSInvalidArgumentException

落ちる。

いつの間にか

落ちなくなってる。(Property〜のエラーは出る)
iOS 13から?

NSNumber.intValue    = 98765
NSString.intValue    = 1234
NSNumber.stringValue = 98765
NSString.stringValue = 01234
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0