我設置我的viewcontrollerA作爲一個單身人士。在viewcontrollerA.h我:使用單身人士分配NSNumber值
@property (nonatomic, assign) NSNumber* showCommentOrCreate;
在viewcontrollerB.m我:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
sharedSingleton.showCommentOrCreate = [NSNumber numberWithInt:2];
在我viewcontrollerB.m我:
PhotoViewController* sharedSingleton = [PhotoViewController sharedManager];
NSLog(@"num %ld", (long)sharedSingleton.showCommentOrCreate);
的問題是,不管是什麼值我以這種方式設置[NSNumber的numberWithInt:整數],我總是得到一些這不是我所設置的號碼:
例如2013年1月24日19:42:24.936飛濺,它[870:907] NUM 475536752
有誰知道爲什麼嗎?
爲什麼你認爲1 。這與Xcode有關,2.(指向)'NSNumber'對象的地址應該與其中包含的值相同? – 2013-01-24 18:50:47
像這樣的東西在Java中工作,但不在Obj-C – nielsbot
@nielsbot:即使在objective-c中,類型轉換也可以工作。即使在Java中,你可以強制轉換'(ComplexNumber)employeeObject':P –