开发者

Compilation error with Xcode 4.2 [closed]

开发者 https://www.devze.com 2023-03-15 13:27 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

ok, I think I am officially going nuts...trying to run this code on xcode 4.2 with iOS 5.0 simulator and getting all sorts of errors. In this app, all I am trying to do is to run the core location API.

My location "controller" class:

.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

I am getting an error in the .m file that "@synthesize locMgr, delegate;" that "Existing ivar 'delegate' for assign property 'delegate' must be _unsafe_unretained"


You should not assign your delegate, rather do

 @property (nonatomic, retain) id delegate;

That should solve your problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消