ios Xcode 6 不会在 Swift 中自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25133039/
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
Xcode 6 isn't autocompleting in Swift
提问by Avner Barr
I am trying to import various libraries which I can't remember their exact name. Unfortunately Xcode6 (using swift
) isn't auto completing them like was done in Xcode5 using objective-c.
我正在尝试导入各种库,但我不记得它们的确切名称。不幸的是,Xcode6(使用swift
)并没有像在Xcode5 中使用 Objective-c那样自动完成它们。
For instance:
例如:
ALAssetsLibrary
MPMediaPlayer
etc.
等等。
I am forced to Google the exact framework name and then go back and copy paste.
我被迫在 Google 上搜索确切的框架名称,然后返回并复制粘贴。
In general autocomplete is working very poorly. Am I doing something wrong in Xcode 6?
一般来说,自动完成的效果很差。我在 Xcode 6 中做错了什么吗?
Should I set any flags in settings to get it to work?
我应该在设置中设置任何标志以使其工作吗?
回答by bWlrYWphdWhvbmVu
This fix from apple dev forums works for me. I have had performance/autocomplete issues since beta 5 i think and now xcode 6.1/Yosemite on my old 2010 MBP is working flawlessly.
来自苹果开发论坛的这个修复对我有用。我认为自 beta 5 以来我一直有性能/自动完成问题,现在我的旧 2010 MBP 上的 xcode 6.1/Yosemite 工作完美。
- Quit Xcode.
- Restart the computer (this is to clear any in-memory caches). ?
- Delete the contents of the DerivedData folder (~/Library/Developer/Xcode/DerivedData)
- [This is the key move:] Delete ~/Library/Caches/com.apple.dt.Xcode.
- 退出 Xcode。
- 重新启动计算机(这是为了清除所有内存缓存)。?
- 删除 DerivedData 文件夹(~/Library/Developer/Xcode/DerivedData)的内容
- [这是关键:] 删除 ~/Library/Caches/com.apple.dt.Xcode。
Now launch Xcode once more…
现在再次启动 Xcode…
回答by Travis M.
This is the same as the correctly chosen answer above but just made slightly easier.
这与上面正确选择的答案相同,但稍微容易一些。
I've had to do it several times and in my testing you can skip restarting your mac.
我不得不多次这样做,在我的测试中,您可以跳过重新启动 Mac 的步骤。
1) Close Xcode
1)关闭Xcode
2) Terminal -> rm -rf ~/Library/Developer/Xcode/DerivedData/*
2) 终端 -> rm -rf ~/Library/Developer/Xcode/DerivedData/*
3) Terminal -> rm -rf ~/Library/Caches/com.apple.dt.Xcode
3) 终端 -> rm -rf ~/Library/Caches/com.apple.dt.Xcode
Restart Xcode and it should be back to normal.
重新启动Xcode,它应该会恢复正常。
回答by Steve Rosenberg
I find that if my deployment target is 8.1 then autocomplete always works. But it is unreliable if it is not.
我发现如果我的部署目标是 8.1,那么自动完成总是有效的。但如果不是,它是不可靠的。
回答by Dardan
The easiest way to improve xCode speed and to reuse the trick is by creating an alias and call it every time you need it:
1.Open Terminal:
2.Type in to your terminal ( or copy and paste ): alias xcodeclean="rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
3.Final step is to type xcodeclean
(Remember: next time when you want to clean the xCode just call xcodeclean
)
提高 xCode 速度和重用该技巧的最简单方法是创建别名并在每次需要时调用它:
1. 打开终端:
2. 输入您的终端(或复制并粘贴):alias xcodeclean="rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
3. 最后一步是键入xcodeclean
(记住:下次要清理 xCode 时只需调用xcodeclean
)
回答by jaco129
I have had this happen quite a bit, and yes making sure you are on the most recent beta version does help. Unfortunately you have to download the newest one through the developer portal each time.
我经常遇到这种情况,是的,确保您使用的是最新的测试版确实有帮助。不幸的是,您每次都必须通过开发人员门户下载最新的。
I have also noticed that the the autocompletion goes away when the swift compiler is struggling with compiling something even though it is error free and if you comment out or remove the right line of code the feature comes back as expected. Most definitely resulting from beta quality software.
我还注意到,当 swift 编译器努力编译某些东西时,即使它没有错误,自动完成功能也会消失,如果您注释掉或删除正确的代码行,该功能会按预期返回。最肯定是由测试版质量的软件产生的。
A last week I was beating my head against the wall because the swift compiler wasn't playing nice with the sqrt()
function. Hopefully these issues are ironed out by the time of full release.
上周,由于 swift 编译器对这个sqrt()
函数的表现不佳,我的头撞在了墙上。希望这些问题在完全发布时得到解决。
Sorry there's no real 'fix' yet!
抱歉,还没有真正的“修复”!
回答by adam10603
Sometimes it doesn't autocomplete for me either. I think this is due to the fact that Xcode 6 is still in beta. Btw, have you been updating Xcode 6 beta? The latest is beta 5 at the moment. I failed to notice for some time that the App Store does not update Xcode 6 beta, so I was stuck with beta 1 for a while. If you haven't been updating it, then do it. Maybe that will help with bugs like this.
有时它也不会自动完成。我认为这是因为 Xcode 6 仍处于测试阶段。顺便说一句,您是否一直在更新 Xcode 6 beta?目前最新的是 beta 5。我有一段时间没有注意到 App Store 没有更新 Xcode 6 beta,所以我被 beta 1 困了一段时间。如果你还没有更新它,那就去做吧。也许这将有助于解决这样的错误。
回答by hris.to
I find this extremely annoying. Posted answer to clear derived data works bulletproof, however you should close xcode before clearing folder. I've made small script to do the work for me.
我觉得这非常烦人。已发布的清除派生数据的答案是防弹的,但是您应该在清除文件夹之前关闭 xcode。我已经制作了小脚本来为我完成这项工作。
#!/bin/bash
echo "Start fixing xCode"
echo "Closing xCode"
osascript -e 'tell app "Xcode" to quit'
sleep 2
echo "Clearing DerivedData..."
rm -rf "$HOME/Library/Developer/Xcode/DerivedData"
sleep 2
echo "Launch xCode again"
osascript -e 'tell app "Xcode" to run'
echo "Finish fixing xCode"
Now whenever xCode gives me a finger I simply run it. The problem that you need to recompile everything however still persists.
现在每当 xCode 给我一个手指时,我只需运行它。然而,您需要重新编译所有内容的问题仍然存在。
EDIT
编辑
Thanks to on suggestion in the comments from @Nikolay Spassov, I adjusted the script to capture your home directory instead of changing it. So below step is no longer neccessary.
感谢@Nikolay Spassov 评论中的建议,我调整了脚本以捕获您的主目录,而不是更改它。所以不再需要下面的步骤。
OLD Step
旧步骤
Please note you have to change '/Users/iphonedev5...' part to make it work in your system :)
请注意,您必须更改“/Users/iphonedev5...”部分才能使其在您的系统中工作:)
回答by Progr3ss
I tried changing the Fonts & Color to default and it worked. I normally have it on MidNight2.
我尝试将字体和颜色更改为默认值并且它起作用了。我通常在 MidNight2 上使用它。
回答by Mo Abdulmalik
If you can't locate all the folders mentioned above or you are too lazy to type in the terminal try the following below:
如果您无法找到上面提到的所有文件夹,或者您懒得在终端中输入,请尝试以下操作:
?Create a new folder on desktop
?在桌面上创建一个新文件夹
?Go to your application folder copy the Xcode application
?转到您的应用程序文件夹复制 Xcode 应用程序
?Paste the application in the folder you created on the desktop
?将应用程序粘贴到您在桌面上创建的文件夹中
*Go back to the application folder again and delete Xcode from the application folder. You can delete the Xcode app by using cleanMyMac2 or any other cleaner app so that all such files like com.apple.Xcode and others with go it.
*再次返回应用程序文件夹并从应用程序文件夹中删除Xcode。您可以使用 cleanMyMac2 或任何其他更清洁的应用程序删除 Xcode 应用程序,以便所有此类文件(如 com.apple.Xcode 和其他文件)随附。
?After you have done that restart your computer
?完成后重新启动计算机
?Go to the folder you created early open Xcode you will see the terms and conditions just accept and start your projects
?转到您创建的文件夹,打开 Xcode,您将看到接受并启动项目的条款和条件
Good Luck
祝你好运
回答by BonanzaDriver
I tried all of these, but to no avail - nothing worked. My situation is I have a Swift class "A" that after performing a large merge into my branch could no longer see several other Swift files ("B" - "F") that were located in a different Group from within my project.
我尝试了所有这些,但无济于事 - 没有任何效果。我的情况是我有一个 Swift 类“A”,在对我的分支执行大型合并后,无法再看到位于我项目中不同组的其他几个 Swift 文件(“B”-“F”)。
What's interesting is "A" belongs to both the main project Target, but also to the UnitTest Target whereas "B", "C", "D", "E", and "F" ONLY belonged to the main project Target.
有趣的是,“A”既属于主项目 Target,也属于 UnitTest Target,而“B”、“C”、“D”、“E”和“F”仅属于主项目 Target。
By including them for membership with the UnitTests also all of a sudden Xcode can now see those classes correctly - must be members in the same Targets, perhaps?
通过将它们包含为 UnitTests 的成员资格,Xcode 现在也可以突然正确地看到这些类 - 也许必须是同一目标中的成员?
The fixed a couple of things: 1) Code completion now works. 2) The little red error markers that are next to the line numbers ("unresolved identifier" errors) cleared up too. This last one was very annoying to me as when you CMD-B to build they clear up and the code compiles just fine / runs just fine. But, make ANY change (add a single white space, for example) and these reappeared all the time (and, of course, Code Completion would stop working again as well).
修复了几件事情:1)代码完成现在可以工作了。2) 行号旁边的小红色错误标记(“未解析的标识符”错误)也清除了。最后一个对我来说非常烦人,因为当您使用 CMD-B 构建它们时,它们会清除并且代码编译得很好/运行得很好。但是,进行任何更改(例如,添加一个空格)并且这些更改会一直重新出现(当然,代码完成也会再次停止工作)。
Not sure if this is a Swift or Xcode issue but this is what fixed it for me.
不确定这是 Swift 还是 Xcode 问题,但这就是为我解决的问题。