2011-06-25 187 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