Reputation: 293
Trying to 'nil' some double variables... but getting the 'Assigning to 'double' from incompatible type 'void *' error...
This is my properties (trying to make a variable type class, that holds global vars so they can be accessed and changed from anywhere in the app):
@property (nonatomic) CGPoint lastP;
@property (nonatomic) double brushR;
@property (nonatomic) double brushG;
@property (nonatomic) double brushB;
@property (nonatomic) double brushW;
@property (nonatomic) double brushO;
@property (nonatomic) BOOL mouseSwiped;
then I synthesis like so: @Synthesis lastP; @Synthesis brushR; etc, etc,
and when I do a cleanup method (as I'm exiting the view and going back to a menu) and try and nil the vars so they can be deallocated via arc brushR = nil; brushG = nil; lastP = nil; etc, etc I get the error I stated above.
Is it easier to just use [view removefromsuperview] in the parent viewcontroller (as all this information is going into a containerView INSIDE of a view controller (that's the way it needs to be, can't get around this)) and will that kill all the variables from the above calss? or do I need to nil them manually?
if I can just use removefromsuperview (from a parent class) (eg, I have a view controller and then a container view inside that controller, when a button is pushed in the PARENT controller, the app uses [childcontroller removefromsuperview]) will that 'kill' ALL objects being used by the childview (as I have a uiImage inside the childview view and it didn't seem to clear the image it was holding from memory when I tried this method).
if I have to nil my vars (and not just nuke the view and remove it from the hirachy) why isn't it letting me do this?
I really hope I'm understandable.
Upvotes: 0
Views: 568
Reputation: 167
Since Double is primitive type , therefore ,we cannot set it as nil. nil or Nil can be set to ObjectType Variable.
Upvotes: 1
Reputation: 2257
For id type objects you use nil. Otherwise for void * (ie a C-style pointer) you can use NULL/ nil
Use brushR = 0;
then it should be fine.
Upvotes: 1
Reputation: 17595
You cann't do this. You can only set nil
to pointers. Primitives cann't fill with nil/NULL
. You may assign simple zero
in these place.
Upvotes: 1
Reputation: 32559
Is it easier to just use [view removefromsuperview] in the parent viewcontroller (as all this information is going into a containerView INSIDE of a view controller (that's the way it needs to be, can't get around this)) and will that kill all the variables from the above calss? or do I need to nil them manually?
If you use ARC
, you don't need to do a cleanup. Runtime will do that for you.
I have a uiImage inside the childview view and it didn't seem to clear the image it was holding from memory when I tried this method
It will be released as long as there are no other strong references to it.
Upvotes: 1
Reputation: 2823
You can never nil primitives only pointers. To explain. nil is of type "void *" and you can not assign void * to type float, double etc. you can only assign void * to pointer types. Since a pointer is an address to some memory when you assign nil to the pointer you are pointing the pointer to some memory space that are reserved for nil.
Upvotes: 1