How to assign a value to a BOOL pointer in Objective-C?

前端 未结 4 635
耶瑟儿~
耶瑟儿~ 2020-12-30 19:11

I\'m having a bit of a confusion on how to assign a value to a BOOL pointer? Here\'s my code:

- (void)locationManager:(CLLocationManager *)manager didUpdateT         


        
相关标签:
4条回答
  • 2020-12-30 19:47

    Could be that you should write

    *initialBroadcast = YES; // Where I'm having troubles
    

    The line before seem to be a standard check to see that the pointer is valid (not nil)

    0 讨论(0)
  • 2020-12-30 19:50

    Change -

    initialBroadcast = YES;
    

    to

    (*initialBroadcast) = YES;
    

    Since, you are assigning value to the location the pointer points to( assuming it is initialized ), initialBroadCast should be dereferenced first.

    0 讨论(0)
  • 2020-12-30 20:00

    You need to say

    *initialBroadcast = YES;
    

    initialBroadcast is a pointer aka memory address. The * gives access to the value at the memory address that the pointer holds. So initialBroadcast is a memory address, but *initialBroadcast is a boolean or char.

    0 讨论(0)
  • 2020-12-30 20:04

    The problem isn't the assignment, it is much more likely that you declared your instance variable to be BOOL *initialBroadcast;.

    There is no reason to declare the instance variable to be a pointer (at least not unless you really do need a C array of BOOLs).. Remove the * from the declaration.

    As well, that will fix your currently incorrect if() test. As it is, it is checking to see if the pointer is set, not the value.

    0 讨论(0)
提交回复
热议问题