Nic*_*oft 0 location struct initialization objective-c 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
Run Code Online (Sandbox Code Playgroud)
PeopleStub.h
#import <Foundation/Foundation.h>
@interface PeopleStub : NSObject {
NSMutableDictionary *people;
}
-(id)initWithCoord:(struct CLLocationCoordinate2D*)coord;
@end
Run Code Online (Sandbox Code Playgroud)
我创建PeopleStub实例的方法:
PeopleStub *peopleStub = [[PeopleStub alloc] initWithCoord:locationManager.location.coordinate;
Run Code Online (Sandbox Code Playgroud)
提前致谢!
您可能希望仅传递CLLocationCooridnate2D,而不是指向与参数相同的指针.所以:
-(id)initWithCoord:(CLLocationCoordinate2D)coord;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
525 次 |
| 最近记录: |