2011-06-25 191 views
2

好吧,我想我正式正在疯狂...尝试在iOS 5.0模拟器上运行xcode 4.2上的此代码并获取各种错误。在这个应用程序中,我试图做的就是运行核心位置API。编译Xcode 4.2的错误

我的位置 “控制器” 类:

.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 ,代表;“ ,“对于指派属性‘代表’现有伊娃‘代理’必须_unsafe_unretained”

+0

这可能不是你的问题,但是ivar和属性之间存在类型不匹配:ivar是一个'id',但属性是'id '。 – zneak

+6

在Apple开发人员论坛上提问,Xcode 4.2未发布,我们无法在这里回答ARC问题。 –

回答

2

你不应该assign您的委托,而做

@property (nonatomic, retain) id delegate; 

这应该解决您的问题。

+0

真棒,谢谢 - 确实如此!现在我根本没有得到位置:(... ... ... ... – TommyG

+0

那么,你是否记得把自己设置为初始化它的类的“控制器”类的代表? – uvesten

+0

像'myController.delegate = self' – uvesten