初始化自定义init会给“initWithCoord:'参数1的不兼容类型”

时间:2011-07-07 21:18:59

标签: objective-c struct initialization location parameter-passing

我使用自定义的initWithCoord创建自己的类,其中一个(struct CLLocationCoordinate2D *)作为参数。

即使我认为我有正确的参数类型,我仍然得到“initWithCoord的参数1的不兼容类型:”我做错了什么:

PeopleStub.m:

#import "PeopleStub.h"


@implementation PeopleStub


-(id)initWithCoord:(struct CLLocationCoordinate2D*)coord{
    if(self = [super init]){
            people = [[NSMutableDictionary alloc] init];

    }

    return self; 

}

@end

PeopleStub.h

#import <Foundation/Foundation.h>


@interface PeopleStub : NSObject {

    NSMutableDictionary *people;

}

-(id)initWithCoord:(struct CLLocationCoordinate2D*)coord;

@end

我创建PeopleStub实例的方法:

PeopleStub *peopleStub = [[PeopleStub alloc] initWithCoord:locationManager.location.coordinate;

提前致谢!

1 个答案:

答案 0 :(得分:6)

您可能只希望传递CLLocationCooridnate2D,而不是指向与参数相同的指针。所以:

-(id)initWithCoord:(CLLocationCoordinate2D)coord;