gpt4 book ai didi

iphone - Xcode 4.2 编译错误

转载 作者:行者123 更新时间:2023-12-03 21:06:40 24 4
gpt4 key购买 nike

好吧,我想我正式疯了...尝试在 xcode 4.2 上使用 iOS 5.0 模拟器运行此代码并收到各种错误。在此应用程序中,我要做的就是运行核心位置 API。

我的位置“ Controller ”类:

.h:

#import Foundation/Foundation.h
#import CoreLocation/CoreLocation.h

@protocol locationReceiverDelegate
@required

- (void)locationUpdate:(CLLocation *)location;
- (void)locationError:(NSError *)error;

@end

@interface locationReceiver : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locMgr;
id delegate;
}

@property (nonatomic, retain) CLLocationManager *locMgr;
@property (nonatomic, assign) id delegate;

@end

.m:

#import "locationReceiver.h"

@implementation locationReceiver

@synthesize locMgr, delegate;


- (id)init
{
self = [super init];
if(self != nil) {
self.locMgr = [[CLLocationManager alloc] init];
self.locMgr.delegate = self;
}

return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// if([self.delegate conformsToProtocol:@protocol(locationReceiverDelegate)]) {
[self.delegate locationUpdate:newLocation];
// }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
// if([self.delegate conformsToProtocol:@protocol(locationReceiverDelegate)]) {
[self.delegate locationError:error];
// }
}


@end

我在 .m 文件中收到错误“@synthesize locMgr, delegate;” “用于分配属性‘委托(delegate)’的现有 ivar‘委托(delegate)’必须是 _unsafe_unretained”

最佳答案

您不应该分配您的委托(delegate),而应该这样做

 @property (nonatomic, retain) id delegate;

这应该可以解决你的问题。

关于iphone - Xcode 4.2 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6475892/

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