在Xcode中编译时swift失败了退出代码1 - 可能与Bridging-Headers有关

Jee*_*eef 45 objective-c core-plot ios swift

我有一个Obj-C项目我正在尝试迁移到Swift.我确实在各种课程中取得了成功,但最近遇到了一个我似乎无法理解的问题.当我尝试编译我当前的代码库时,我得到以下内容(SUPER UNHELPFUL ERROR MESSAGE)

命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc失败,退出代码为1

在此输入图像描述

我唯一的假设是它与我的桥接标题有某种关系,但是Xcode没有给我足够的信息来弄清楚这是否真的如此.

我正在使用Cocoapods添加CorePlot到我的项目.我正在尝试将以下类迁移到Swift:

Obj-C类(ScatterPlotContainer.h)

#import <Foundation/Foundation.h>

@class CPTScatterPlot;

@interface ScatterPlotContainer : NSObject
@property (nonatomic, strong) CPTScatterPlot *ahrsAlt;
@property (nonatomic, strong) CPTScatterPlot *calibration;
@property (nonatomic, strong) CPTScatterPlot *coreAlt;
@property (nonatomic, strong) CPTScatterPlot *pitch;
@property (nonatomic, strong) CPTScatterPlot *roll;
@property (nonatomic, strong) CPTScatterPlot *slip;
@end
Run Code Online (Sandbox Code Playgroud)

Obj-c类(ScatterPlotContainer.m)

#import <CorePlot/CPTScatterPlot.h>
#import "ScatterPlotContainer.h"


@implementation ScatterPlotContainer {

}
@end
Run Code Online (Sandbox Code Playgroud)

快速转换

import Foundation

 class ScatterPlotContainer : NSObject {
    public var ahrsAlt : CPTScatterPlot;
    public var calibration : CPTScatterPlot;
    public var coreAlt : CPTScatterPlot;
    public var pitch : CPTScatterPlot;
    public var roll : CPTScatterPlot;
    public var slip : CPTScatterPlot;
}
Run Code Online (Sandbox Code Playgroud)

我的桥接头文件

#import <CorePlot/CPTScatterPlot.h>
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的

当我#import <CorePlot/CPTScatterPlot.h>从桥接头文件中注释掉时- 我在swift中收到错误,因为它不知道CPTScatterPlot是什么

我也试过#import <CPTScatterPlot.h>哪个也没用.

思考

所以我唯一能想到的可能就是因为我正在使用一个可可粉盒,我需要添加一些模块名称.错误消息确实没那么有用.有没有人建议我做过一些明显的错误,或者如何获得更具描述性的错误信息来弄清楚发生了什么?

Kam*_*pai 43

我做了同样的答案,但我的问题没有得到解决.我确实发现这个问题与破坏的函数调用有关.

函数语法没有错,但它的调用机制是错误的.

要检查此问题的确切错误,请检查以下内容:

选择问题导航器>单击错误将显示错误日志>在其中选择所有消息选项卡.

这将显示此错误的所有详细日志.

在此输入图像描述

向下滚动,在我的案例中你得到的日志就像

在此输入图像描述

因此,通过阅读本文,我发现函数调用有问题.我浏览我的代码并解决它,下面是正确和错误的代码.

错误道:

var region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span)
// It will not shown error here but when you build project compiler shows error.
Run Code Online (Sandbox Code Playgroud)

正确的方法:

let region = MKCoordinateRegion(center: self.mapView.userLocation.coordinate, span: span)
Run Code Online (Sandbox Code Playgroud)


Ste*_* S. 8

我昨晚碰到了这个,上面没有任何东西可以解决我的问题.我在笔记本电脑上做了一些非常糟糕的事情,当我看到,纯粹的运气,ONE(1)文件是文本编码设置为UTF-16?!?!WTF?

在此输入图像描述

这是我正在处理的最后一个文件,可能是一个坏的剪切/粘贴"导入"一个奇怪的角色进入竞技场.我在这个文件中将我的代码剪切/粘贴到裸骨文本编辑器中.我删除了文件,重新创建它并粘贴我的代码......然后瞧!这行得通.

这样做,但也检查你的文件编码!:-)