Objective C convert number to NSNumber

前端 未结 5 584
情深已故
情深已故 2021-01-03 19:43

Why doesn\'t this please the compiler? Casting is supposed to work like in C as I can read here How to cast an object in Objective-C.

[p setAge:(NSNumber*)10         


        
5条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 20:27

    Use this:

    [p setAge:[NSNumber numberWithInt:10]];
    

    You can't cast an integer literal like 10 to a NSNumber* (pointer to NSNumber).

提交回复
热议问题