ios Xcode 6 编译 GM 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25776445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:21:30  来源:igfitidea点击:

GM release of Xcode 6 compile

iosxcodeswift

提问by bhzag

I just downloaded the GM release of Xcode 6 and it won't compile with this error:

我刚刚下载了 Xcode 6 的 GM 版本,它不会编译出现此错误:

Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

Any ideas on how to fix this?

有想法该怎么解决这个吗?

回答by Maxwell

This error can happen for numerous reasons, so this is meant to be a debugging hint. You may want to try using xcodebuildin the command line. It will give you details as to what files are the culprits.

发生此错误的原因有很多,因此这是一个调试提示。您可能想尝试xcodebuild在命令行中使用。它将为您提供有关哪些文件是罪魁祸首的详细信息。

To do this, open Terminal and go to your project folder. Once there, type in

为此,请打开终端并转到您的项目文件夹。在那里,输入

xcodebuild -project YourProject.xcodeproj -scheme YourScheme

or if you're working in a workspace

或者如果您在工作区工作

xcodebuild -workspace YourProject.xcworkspace -scheme YourScheme

You may see A LOT of messages pop up, but at the very end of the output you should see the specific files that are causing the crash. Back in XCode, go into those files and start playing with some of the Swift syntax to see what's going on. In my case, it had to do with the setAttributeString function, but I've seen other people have issues with ! and ?.

您可能会看到很多消息弹出,但在输出的最后,您应该会看到导致崩溃的特定文件。回到 XCode,进入这些文件并开始使用一些 Swift 语法来看看发生了什么。就我而言,它与 setAttributeString 函数有关,但我看到其他人对 ! 和 ?。

Hopefully that will get you headed in the right direction.

希望这会让你朝着正确的方向前进。

回答by Byron Coetsee

I had to change my "Optimization Level" to None[-0none]

我不得不将我的“优化级别”更改为无 [-0none]

Target > Build Settings > Swift Compiler > Optimization Level.

目标 > 构建设置 > Swift 编译器 > 优化级别。

回答by Micha? Kreft

My case was a little bit different and it involves enums and optionals. For the simplicity lets define

我的情况有点不同,它涉及枚举和选项。为了简单起见,让我们定义

enum Animal {
    case Dog
    case Cat
}

func exampleAction(animal: Animal) {}

exampleAction(.Cat)

It will run OK. However as soon as I made the argument optional the error started to appear. So this code won't work:

它会运行正常。但是,一旦我将参数设为可选,错误就开始出现。所以这段代码不起作用:

func exampleAction(animal: Animal?) {}

exampleAction(.Cat)

To make it work I had to add explicit enum name in the method call. So the following code worked again:

为了使它工作,我必须在方法调用中添加显式枚举名称。所以下面的代码再次起作用:

exampleAction(Animal.Cat)

回答by tounaobun

I think it occured for many reasons, what I have encountered is this situation,hope it could help you.

我认为它的发生有很多原因,我遇到的是这种情况,希望它可以帮助你。

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) ){ [weak self] in

        // ...
        dispatch_async(dispatch_get_main_queue()) { [weak self] in

            // ...
            return

        }
    }

In the upper code,just delete "[weak self]" called capture list will remove the compiler error. It works for me.

在上面的代码中,只需删除名为捕获列表的“[弱自我]”即可消除编译错误。这个对我有用。

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) ){ [weak self] in

        // ...
        dispatch_async(dispatch_get_main_queue()) {

            // ...
            return

        }
    }

xCode version is 6.1.1

xCode 版本是 6.1.1

回答by tuoxie007

May be the same issue Swift compile error in XCode 6 GM

可能是XCode 6 GM 中的 Swift 编译错误相同的问题

I had the same problem, then I use git checkout old versions to find which commit cause the problem, and try to find the key problem code. My key problem code is something like this

我也遇到了同样的问题,然后我使用git checkout old versions查找导致问题的提交,并尝试找到关键问题代码。我的关键问题代码是这样的

func afunc() {
    class AClass() {
    }
    let ac = AClass()
    //....
}

Other code could make the same problem, occur in Swift Optimization, and swift compiler doesn't tell you the exact location. This must be a bug by Apple.

其他代码可能会出现同样的问题,发生在 Swift 优化中,而 Swift 编译器不会告诉您确切的位置。这应该是苹果的bug。

回答by Weles

In my case i changed 3 places:

就我而言,我更改了 3 个地方:

Target > Build Settings > Swift Compiler >

目标 > 构建设置 > Swift 编译器 >

  • Optimization Level.
    • Debug: None [-Onone]
    • Distribution: Fastest [-O]
    • Release: Fastest [-O]
  • 优化级别。
    • 调试:无 [-Onone]
    • 分布:最快 [-O]
    • 发布:最快 [-O]

When i changed just Debug, i have errors like "Source Kit crashed...." This combination of parameters, works very good for me!

当我只更改 Debug 时,出现诸如“Source Kit crashed....”之类的错误,这种参数组合对我来说非常有用!

回答by evanchin

If you are using some API which should be used in early iOS version, you may get build failure. For example: If you are using UI_USER_INTERFACE_IDIOM() instead of UIDevice.currentDevice().userInterfaceIdiom to identify the device type, you will get this build error with no hint.

如果你使用了一些应该在早期 iOS 版本中使用的 API,你可能会遇到构建失败。例如:如果你使用 UI_USER_INTERFACE_IDIOM() 而不是 UIDevice.currentDevice().userInterfaceIdiom 来识别设备类型,你会得到这个没有提示的构建错误。

回答by TPot

A lot of people have this issue (me included) due to the optimisation on the compiler. I don't consider turning off the optimisation a correct resolution - I want my code optimised to run as quick as it can.

由于编译器的优化,很多人(包括我在内)都有这个问题。我不考虑以正确的分辨率关闭优化 - 我希望我的代码优化后尽可能快地运行。

re-running xcodebuild manually didn't do any good as it ran it without the optimisations as well.

手动重新运行 xcodebuild 没有任何好处,因为它在没有优化的情况下运行它。

However - the error screen gave me the swiftc command that was failing:

但是 - 错误屏幕给了我失败的 swiftc 命令:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -target arm64-apple-ios8.0 -incremental -module-name SpaceCats -O -sdk /Applic...

The -Othere is the optimise flag.

-O存在的优化标志。

I re-ran this whole command in the projects directory (as per xcodebuild recommendation above) and amongst all the details I found the error below:

我在项目目录中重新运行了整个命令(按照上面的 xcodebuild 建议),在所有细节中,我发现了以下错误:

{
"kind": "finished",
"name": "compile",
"pid": 10682,
"output": "Bitcast requires both operands to be pointer or neither\n  %228 = bitcast i8* %227 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %324 = bitcast i8* %323 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %411 = bitcast i8* %410 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %498 = bitcast i8* %497 to %VSs20UnsafeMutablePointer, !dbg !1322\nLLVM ERROR: Broken function found, compilation aborted!\n",
"exit-status": 1
}

If you want it to go to a file instead of the screen, add " 2>filename" to the end.

如果您希望它转到文件而不是屏幕,请在末尾添加“2>filename”。

I then had to find the pid (10682) in the file to see what it was compiling. I ran the command for that pid manually and it gave me the error for the specific file. Then it comes down to fixing the code.

然后我必须在文件中找到 pid (10682) 以查看它正在编译的内容。我手动运行了该 pid 的命令,它给了我特定文件的错误。然后归结为修复代码。

回答by Julian Król

I see many reasons. My answer is not a generic solution but just adding yet another case that provide to that error. In my case it was setting a button's title like this:

我看到很多原因。我的答案不是通用解决方案,而只是添加了另一个提供该错误的案例。就我而言,它正在设置一个按钮的标题,如下所示:

button!.setTitleColor(.whiteColor(), forState: UIControlState.Normal)

instead of this:

而不是这个:

button!.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)

回答by Vladimir Linkevich

In my case this error was caused by the incorrect (UTF8) .swift file encoding; Solved by copy-pasting the file's contents into a new file.

就我而言,此错误是由不正确的 (UTF8) .swift 文件编码引起的;通过将文件的内容复制粘贴到新文件中来解决。