【发布时间】:2011-06-25 04:47:48
【问题描述】:
好的,我想我正式发疯了...尝试使用 iOS 5.0 模拟器在 xcode 4.2 上运行此代码并遇到各种错误。在这个应用程序中,我要做的就是运行核心位置 API。
我的位置“控制器”类:
.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
我在“@synthesize locMgr, delegate;”的 .m 文件中遇到错误即“分配属性 'delegate' 的现有 ivar 'delegate' 必须是 _unsafe_unretained”
【问题讨论】:
-
这可能不是您的问题,但 ivar 和属性之间存在类型不匹配:ivar 是
id,但属性是id<locationReceiverDelegate>。 -
在 Apple 开发者论坛上提问,Xcode 4.2 尚未发布,我们无法在这里回答 ARC 问题。
标签: iphone objective-c compiler-construction xcode4 location