Swift Xcode 인덱스 동결 또는 느림
아마도 이것은 내가 그런 성가신 "기능"을 경험하고있는 것일 수도 있습니다.
Xcode 6.0.1에서 Xcode 6.1로 업그레이드 한 후 상황이 변경되었습니다. Xcode 6.1은 프로젝트를 영원히 인덱싱하거나 소스 파일을 컴파일합니다. 이 프로젝트는 큰 프로젝트가 아닙니다. 작업 공간에 Swift 파일과 AWS SDK 2.0 Cocoapods가 포함되어 있습니다. 나는 그것이 전체가 매끄럽게 인덱싱되고 컴파일되는 것을 막아야한다고 생각하지 않는다. Xcode 6.1이 어떻게 작동하는지 확인하기 위해 aws-sdk-ios-samples 몇 개를 사용해 보았습니다.
지금까지 시도한 솔루션 :
- 오거나이저에서 "파생 데이터"를 삭제하고 작업 영역을 다시 엽니 다. (고치지 못함)
- .xcodeproj 파일에 "Show Package Contents"및 .xcworkspace 삭제 ( Xcode 4-성능 저하 )
불행히도 그들 중 누구도 일하지 않았습니다.
추신 : 프로젝트를 다시 만들어야할까요? 내 컴퓨터 설정 : MacBook Pro (Retina, 13 인치, Mid 2014), 메모리 8GB 1600MHz DDR3, Yosemite. (이 작은 프로젝트를 실행하기에 충분하다고 생각합니다.)
파일 분할, Xcode 6.2 베타 설치 및 문자열 연결 구문 중단을 포함하여 위의 많은 제안을 시도했습니다. 마침내 나를 위해 한 일은 테스트 데이터에 사용하던 사전 리터럴 선언의 배열을 여러 .append
문 으로 분할하는 것이 었습니다 .
// This causes indexing/building to hang...
var test = [ [ "a": false, "b": "c" ],
[ "a": false, "b": "c" ],
[ "a": false, "b": "c" ],
[ "a": false, "b": "c" ],
[ "a": false, "b": "c" ],
[ "a": false, "b": "c" ] ]
// This works fine.
var test = [ [ "a": false, "b": "c" ] ]
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
test.append([ "a": false, "b": "c" ])
또한,이 배열의 여섯 번째 항목이 저에게 문제를 일으키는 원인이됩니다. 5 개는 잘 작동합니다.
나에게 유일한 해결책은 모든 파생 데이터를 삭제 한 다음 (현재 프로젝트뿐만 아니라 전체 폴더를 정리하는 것) Xcode를 다시 시작하는 것입니다.
Xcode에서 파일 열기 / 환경 설정
팝업 창의 맨 오른쪽에있는 위치를 클릭합니다.
"/ Users / Mac / Library / Developer / Xcode / DerivedData"옆에있는 작은 화살표 아이콘을 클릭하면 DerivedData 폴더 (이전 프로젝트의 모든 파생 데이터가 포함 된 Xcode 폴더)로 이동합니다. .)
DerivedData 폴더 삭제
CocoaPods를 사용하고 있습니까? 나는 오늘 일찍 같은 문제를 만났습니다. (xCode 6.1.1 사용)
문제를 해결하기 위해, 프로젝트 디렉토리 ~/Library/Developer/Xcode/DerivedData
의 Pods
폴더 및 <project>.xcworkspace
.
그런 다음 터미널을 열고 프로젝트 디렉토리로 이동 한 다음 pod install
다시 실행 했습니다.
오늘도 같은 문제가있었습니다. Xcode 6.3.2, 중간 크기의 Swift 프로젝트. 어느 시점에서 인덱싱을 시작했지만 인덱싱이 끝나지 않았습니다. 그 원인이 된 코드는 [String : [String]] 유형의 사전이므로 문자열 배열을 값으로 사용하는 문자열 키 사전입니다. A에서 Z까지의 키가있는이 중 두 개가 있었고이 26 개 항목 각각에는 5-10 개의 문자열이있는 문자열 배열이 포함되어 있습니다.
파생 데이터를 지우는 것은 도움이되지 않았습니다. 그 딕셔너리를 주석으로 만 다시 처리했습니다.
솔직히 말도 안돼! Apple은 Xcode를 수정해야합니다! Swift 프로젝트를 컴파일 할 때 이미 끔찍하게 느리지 만 이와 같은 버그는 눈에 띕니다. 나는 이것으로 내 일을 제대로 할 수 없다!
여전히이 문제가있는 사람들을 위해 이것은 개체를 하나씩 입력하지 않아도되는 해결 방법입니다.
// instead of this, which freezes indexing
let keys = [keyQ, keyW, keyE, keyR, keyT, keyY, ... keyM]
// and instead of this, which is ugly & lengthy
var keys = [KeyboardKey]()
keys.append(keyQ)
keys.append(keyW)
...
keys.append(keyM)
// use this:
var keys = [KeyboardKey]()
keys.appendContentsOf([keyQ, keyW, keyE, keyR, keyT, keyY, ... keyM])
For me, I tried all the above with no success; but all I had to do was to delete the derived data folder, then open up another random project, wait for it to index and now my original (malfunctioning) project works!
Do the development world a favour apple and make your swift compilers open source- so we are not all thwarted by your incompetence.
I am using Xcode Version 7.3 (7D175)
I think I might have figured out an underlying problem. There where two instances where I got stuck in the indexing phase:
I created a closure that I assigned to a variable and omitted the type signature. I think xcode had issues with that type inference step. If I remember correctly one of the arguments was a CGPoint, which has an overloaded constructor. My hypothesis is that there where too many possibilities of what my closure might accept as arguments.
I refactored a factory method such that instead of returning instances of one type, it could return instances of many types with a common base class. It appears that wherever I used the factory method, I had to cast the resulting object to a specific type (either with as? or by assigning it to a variable that accepts a specific type) Again the type inference step seems to be broken.
It seems like the same is going on with the dictionary declarations mentioned by earlier individuals. I filed a bug report with apple.
I experienced this same issue after upgrading to 6.1. Xcode would get stuck compiling or indexing without generating a specific error message.
이 문제는 신속한 파일의 긴 표현 중 일부를 여러 개의 짧은 표현으로 분할하여 마침내 해결되었습니다. 내 프로그램의 일부는 다양한 문자열 변수를 결합하여 긴 문자열을 형성합니다. 단일 표현식으로 결합하려는 시도와 더하기 할당 연산자를 사용하려는 시도는 모두 실패했습니다. 다음과 유사한 작업을 수행하여 작동하도록 만들 수있었습니다 (간체).
var a = "Hello"
var b = " "
var c = "World"
var d = "!"
var partA = a + b
var partB = c + d
var result = partA + partB
이 아이디어는 이전 Xcode 버전에서 "표현식이 너무 복잡해서 적절한 시간에 풀 수 없습니다. 표현식을 별개의 하위 표현식으로 나누는 것을 고려하십시오."
도움이 되었기를 바랍니다
I've struggled with the same problem. I've tried the two solutions mentioned ( deleting derived data and deleting .xcworkspace ) with no success. I also tried slowly commenting out most of the code bit by bit and removing the files until there was almost nothing left and the indexing was still stuck.
I did find a solution that worked for me, I've opened the project with an older Xcode Version 6.1 (6A1030) which had no problem indexing then got back to the latest Xcode Version 6.1 (6A1052d) which I was using before and indexing was fixed and continued to work well.
My conclusion is that this is a bug with Xcode Version 6.1 (6A1052d) which I hope will improve with future releases.
The problem does come back once in a while, the same fix works each time. I guess another solution would be to just stick with the older Xcode Version 6.1 (6A1030) but it won't work with devices running iOS 8.1 and it won't have the latest bug fixes.
Finally, I "solved" the issue, though it is just a workaround.
I created another project and added files one by one to it. Then I spotted a "very long" viewcontroller.swift file. Then I broke its codes into modules and made those repeatedly used codes into functions in another swift file. And also, I took the suggestion online that long expression should be broken into shorter ones. Then, the indexing works and the compiling works.
So for now, I have it "solved".
BUT, I don't think this is right. Xcode IDE should be more than capable of handling my "very long" swift file, only 1500 lines. I believe this is definitely a bug (existing for a long time), although Xcode 6.1 is already an upgrade from Xcode 6.0.1.
For me, I deleted the Xcode app and downloaded it again and install it. That solved the issue, at least over now.
On my Xcode the solution was to close all redundant windows.For some reason many open windows make XCode very slow.
Xcode indexing usually for your code for suggestions and auto complete among other things like helping you in story boards and vice versa. But to make faster your xcode project you can turn it off/on via terminal
Turn off indexing
defaults write com.apple.dt.XCode IDEIndexDisable 1 Turn on indexing defaults write com.apple.dt.XCode IDEIndexDisable 0
But Better approach to use a speedy mac with good RAM.
I have tried this with Xcode 8.3.3. Here are my results:
You can write perfectly fine Swift code that will cause indexing to hang.
Once indexing hangs, it hangs. Changing the Swift code back to something that wouldn't cause indexing to hang doesn't help, it still hangs.
Closing the project and reopening doesn't help in that situation.
Quitting Xcode and restarting it helps. Indexing will not hang anymore (that is if you changed the code back to something that doesn't make it hang).
Restarting your Mac helps as well, although it isn't needed.
The hanging is caused by perfectly fine Swift code. An example that I had looked like
if let date = function1()
?? function2()
?? function3()
?? function4()
?? function5()
?? function6()
?? function7()
?? function8()
?? function9()
?? function10() {
return date
}
Indexing would hang. I commented out most of the "??" lines and it was fine (after quitting and relaunching Xcode). Uncommented one line after the other. With some number of lines it was fine, then uncommenting the next line would make it hang.
The only thing that helps apparently is changing your code.
I've had this issue as well and solved it by removing/changing expressions with the "+" operator.
I swear changing this:
var mainArray = arrayOne + arrayTwo + arrayThree + arrayFour + arrayFive
To this:
var mainArray = arrayOne
mainArray += arrayTwo
mainArray += arrayThree
mainArray += arrayFour
mainArray += arrayFive
solved the problem. I realize that sounds crazy but it was true for me.
My machine is a maxed out MBP late 2013
The Xcode 6.2 beta resolved the issue for me. Not lightning fast, but at least it isn't indexing forever. The beta does not install over the top of your regular Xcode installation, so if you don't don't like the beta, you can just delete it.
Various Xcode downloads including the beta >
You may wish to update to Xcode 6.1.1
It has been officially released and resolved for us the indexing problem. In the update description it says that they have applied stability fixes so it is very likely that it will behave in a more stable fashion.
Wish you luck with this saga!
If you don't mind reverting back to 6.0.1 until they figure it out, that's what worked for me. I was having the same issue with both 6.1 and 6.1.1. Now I'm good. I'll try 6.2 when it comes out.
You can find previous versions of apple software on their official dev site, here: https://developer.apple.com/downloads/index.action
If you do this, make sure to delete your current copy of Xcode first.
I am using Xcode 6.1.1 with swift files on the same exact MacBook Pro.
As I kept adding rows into a 3D string array, Xcode all of sudden became unusable and now I can't do anything.
Will try to revert to 6.1 and hopefully the problem will go away.
I am seeing this in Xcode 6.3.2. I had really hoped that a year after release, they would have the compiler working, but alas.
If none of the above solutions work for, try checking your code for syntactic errors. In the process of refactoring, I extracted a closure but forgot to qualify the parameters:
let hangsInsteadOfError = { l, r in
return l.nameFirst < r.nameFirst
|| l.nameFirst == r.nameFirst && l.nameLast < r.nameLast }
let fixingErrorAvoidsHang = { (l:User, r:User) -> Bool in
return l.nameFirst < r.nameFirst
|| l.nameFirst == r.nameFirst && l.nameLast < r.nameLast }
If I have learned anything from working in Swift, it is to work incrementally, to avoid having to backtrack too much to find the offending code.
- Is your indexing status is a "Indicator circle" or "Progress bar"?
- If it is a "Indicator circle", that means it already stuck at the beginning.
- Open and check with your other projects, if they are all the same, that mean it's a system issue.
- Just restart your computer and everything will be fine.
I use Xcode 8.2 and also ended in this problem. It started after I defined a complex tuple variable -- an array of tuple with subarray of tuple. Things gets really slow when the subarray of tuple has property that is programmatically calculated.
As some other answers noted, the indexing takes forever, and I believe it is trying infer the types the variable.
I solved the problem first by clearly define the variable with types included. When updating property, I calculate it first then assign it to the tuple, instead of calculating in defining the variable.
Here is an example code.
var sectionTuples: [(section: String, rows: [(name: String, subtitle: String)])] = []
let subtitle1: String = "" // something calculated dynamically
let subtitle2: String = "" // something calculated dynamically
sectionTuples = [(
section: "Section 1", rows: [
(name: "name1", subtitle: subtitle1),
(name: "name2", subtitle: subtitle2)
])]
The bottom line is don't let Xcode infer complex structures.
I was having same issue. My xCode is 8.2.1. But in my case I wanted to create an array of dictionary with 33 key-value pairs. I was doing in following way which was stuck in indexing:
var parameter = [String : AnyObject]()
var finalArray = [parameter]
for item in listArray
{
parameter = ["A": item.a as AnyObject, "B": item.b as AnyObject, "C": item.c as AnyObject, ... , "Z": item.z as AnyObject]
finalArray.append(parameter)
}
Following worked for me:
var parameter = [String : AnyObject]()
var finalArray = [parameter]
for item in listArray
{
parameter["A"] = listArray.a as AnyObject
parameter["B"] = listArray.b as AnyObject
parameter["C"] = listArray.c as AnyObject
parameter["D"] = listArray.d as AnyObject
.
.
.
parameter["Z"] = listArray.z as AnyObject
finalArray.append(parameter)
}
참고URL : https://stackoverflow.com/questions/26494082/swift-xcode-index-freezing-or-slow
'Programming' 카테고리의 다른 글
CMake에서 include_directories와 target_include_directories의 차이점은 무엇입니까? (0) | 2020.08.20 |
---|---|
HTML 이미지 크기 조정 (0) | 2020.08.20 |
자바 스크립트 시작 부분에서 세미콜론을 시작하는 목적은 무엇입니까? (0) | 2020.08.20 |
tmux : 2 개의 열린 창을 나란히 배치하는 방법은 무엇입니까? (0) | 2020.08.20 |
Python의 최대 공약수 코드 (0) | 2020.08.19 |