在Swift中调用Objective-C init方法不起作用

时间:2017-04-15 20:56:41

标签: ios objective-c swift coordinates utm

我正在尝试使用此API转换坐标:https://github.com/palmerc/GeodeticUTMConverter

它有一个Objective-C类头,名为" GeodeticUTMConverter.h"其中包括:

@interface GeodeticUTMConverter : NSObject

@property (nonatomic, assign) UTMDatum utmDatum;

+ (CLLocationCoordinate2D)UTMCoordinatesToLatitudeAndLongitude:(UTMCoordinates)UTMCoordinates;
+ (UTMCoordinates)latitudeAndLongitudeToUTMCoordinates:(CLLocationCoordinate2D)latitudeAndLongitudeCoordinates;

- (id)initWithDatum:(UTMDatum)datum;

- (CLLocationCoordinate2D)UTMCoordinatesToLatitudeAndLongitude:(UTMCoordinates)UTMCoordinates;
- (UTMCoordinates)latitudeAndLongitudeToUTMCoordinates:(CLLocationCoordinate2D)latitudeAndLongitudeCoordinates;
@end

实施" GeodeticUTMConverter.m":

@implementation GeodeticUTMConverter

+ (CLLocationCoordinate2D)UTMCoordinatesToLatitudeAndLongitude:(UTMCoordinates)UTMCoordinates
{
    GeodeticUTMConverter *utmConverter = [[GeodeticUTMConverter alloc] init];
    CLLocationCoordinate2D latLong = [utmConverter UTMCoordinatesToLatitudeAndLongitude:UTMCoordinates];
    return latLong;
}

+ (UTMCoordinates)latitudeAndLongitudeToUTMCoordinates:(CLLocationCoordinate2D)latitudeAndLongitudeCoordinates
{
    GeodeticUTMConverter *utmConverter = [[self alloc] init];
    UTMCoordinates utmCoordinates = [utmConverter latitudeAndLongitudeToUTMCoordinates:latitudeAndLongitudeCoordinates];
    return utmCoordinates;
}



- (id)init
{
    self = [super init];
    if (self != nil) {
        UTMDouble equitorialRadius = 6378137;
        UTMDouble polarRadius = 6356752.3142;
        UTMDatum wgs84datum = UTMDatumMake(equitorialRadius, polarRadius);

        _utmDatum = wgs84datum;

        _utmScaleFactor = 0.9996;
    }

    return self;
}

我试图在我的swift代码中使用两个转换函数,所以我尝试使用swift创建它的实例:

var instance = GeodeticUTMConverter()

但是我得到了一个"使用未解析的标识符"错误。我查看了很多SO帖子,以确保我的桥接标题是正确的。它在我的构建设置中正确列出,我以下列方式使用目标C头文件的名称:

#import "GeodeticUTMConverter.h"

所有文件都在同一个文件夹中,所以我觉得我必须对我的Swift语法做错了。虽然我在谈论这个话题,但是有谁知道我将如何制作一个" UTMCoordinates"快速变量?它在GeodeticUTMConverter.h文件中有一个typedef:

typedef double UTMDouble;
typedef unsigned int UTMGridZone;

typedef enum {
    kUTMHemisphereNorthern,
    kUTMHemisphereSouthern
} UTMHemisphere;

typedef struct {
    UTMDouble northing;
    UTMDouble easting;
    UTMGridZone gridZone;
    UTMHemisphere hemisphere;
} UTMCoordinates;

typedef struct {
    UTMDouble equitorialRadius;
    UTMDouble polarRadius;
} UTMDatum;

0 个答案:

没有答案