gpt4 book ai didi

objective-c - 如何在 Objective-C 中为 BOOL 指针赋值?

转载 作者:IT老高 更新时间:2023-10-28 11:48:36 26 4
gpt4 key购买 nike

我对如何为 BOOL 指针赋值有点困惑?这是我的代码:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
self.latitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
self.longitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];

if (!initialBroadcast) {
initialBroadcast = YES; // Where I'm having troubles

[broadcastTimer fire];
};
}

编译器不断告诉我:Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'signed char *') from 'BOOL' (aka 'signed char') .

由于我是 nubski,因此我希望能对此进行澄清。


更新

正如你们中的许多人所指出的,我显然滥用了 BOOL 的声明。通过使用它的指针。老实说,我不知道我为什么要使用它,但由于我是 Objective-C 的新手,所以它一定对我正在做的事情有用,所以它卡住了。

无论如何,我已经将声明更改为:

//  In .h
@interface ... {
BOOL initialBroadcast;
}

@property BOOL initialBroadcast;

// In .m
@synthesize initialBroadcast;

那么,我现在走对了吗?

最佳答案

你需要说

*initialBroadcast = YES;

initialBroadcast 是一个指针,也就是内存地址。 * 可以访问指针所保存的内存地址处的值。所以initialBroadcast是一个内存地址,但是*initialBroadcast是一个 bool 值或者char。

关于objective-c - 如何在 Objective-C 中为 BOOL 指针赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5364506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com