SourceKitService Terminated - ios

I am having a issue with Xcode where the error "Source Kit Service Terminated" is popping up and all syntax highlighting and code completion is gone in Swift. How can I fix this?
Here is an example image:

The answer to mine (Xcode6-Beta7) was simply to delete the Derived Data folder.
Preferences > Locations > Derived Data > click the arrow to open in Finder > trash it.
There's obviously many reasons why this crash can occur.

I believe I may have found a more general purpose solution. Below are the steps I used to encourage Xcode not to produce the SourceKitService Terminated error.
The symptoms I was having:
When I would start up a new playground, I would receive an error about not being able to communicate with the playground (Error running playground: Failed prepare for communication with playground. See this image on twitter.
When I would switch the playground from OS X to iOS, I would receive another error (unfortunately I did not write that one down).
When I would start to type in an iOS based Swift project, attempting to use code completion/intellisense on any UIKit specific class, I would receive the SourceKitService Terminated issue in this thread.
Debugging process:
I started by looking through google for SourceKitService, this got very little.
I then started monitoring Console.app while using Xcode. This showed a couple errors:
IDEPlaygroundDocument: Error encountered running playground
com.apple.CoreSimulator.CoreSimulatorService[3952]: The runtime for the selected device is not installed.
What I did to correct this issue.
If you are only having an issue within the context of a Swift project, try this alone first. If that doesn't work, then try all of the steps further below.
Open your project and change the target's deployment target to something <= 7.1.
The more lengthy and involved process.
(The first 3 steps are not for sure helpful, but I did them, and so record them here)
Completely delete all copies of Xcode on your system.
Restart your computer.
Reinstall Xcode6-beta only.
Verify that you still have the issue in playground and/or projects.
Open iOS Simulator.
Hardware -> Device -> Manage Devices
Remove all devices.
Recreate all devices you want. I appended the iOS version to the end of the name, just because.
Restart Xcode and the simulator.
Verify that at least playgrounds no longer throw issues when switched from OS X to iOS.
Open your project and change the target's deployment target to something <= 7.1.
Analysis
It appears the issue is with Xcode6 not being able to properly find, and connect, to the simulator. I have not been able to determine why this is the case, but this has allowed me to continue developing with Swift. This may have to do with the fact the simulator binaries seem to have moved.

You just need to delete the "ModuleCache", this is some kind of cache used by Xcode for Autocompletion.
Copy and paste the following line in the Terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache

SourceKitService crashes on my system as soon as I type
extension foo {
I'm using Xcode 6 beta 6 and it does not matter if I type it into an empty file or add it to an existing one. As soon as the source contains one extension block, it will crash. This happens even on newly created projects.
My "solution" is to avoid extension in the sources I'm currently working on. I comment out the end of a class block and the beginning of the extension block. As soon as I have finished my work on the class, I comment them in again:
class MyClass {
[... my stuff ...]
//}
//
//extension MyClass {
}

It started happening on my spritekit project after inserting the touchesMoved-function. This function uses forced unwrapping, which seems to cause the problem:
override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!)
After removing the exclamation marks and thus stopping forced unwrapping, the SourceKitService stopped crashing.
Hope this helps!

I found a solution on Apple's Developer Forums (which requires login, so I'll explain it here too).
TLDR: Don't import a #protocol in your Objective-C to Swift bridging header that is named the same as an #interface. For example, the Facebook SDK has both a protocol and an interface named "FBGraphObject".
Here's the forum post:
Adding Facebook SDK causes SourceKitService to crash. If you want to use beta 3 and you need Facebook SDK, one work around that I found and is working for me is refactoring Facebook SDK's #protocol FBGraphObject and renaming it to something like #protocol FBGraphObjectProtocol as an #interface FBGraphObject also exists and apparently SourceKit doesn't like it.
It sure is a temporary solution just to keep you functional and you'll have to use Cocoapods or otherwise build Facebook SDK yourself rather than using the framework library.
For the time being, you'll need to make sure you don't have conflicting #protocol and #interface declarations and that includes 3rd party libraries you may be using.
This cost me today, hope it helps!
Posted by e.parto on July 10, 2014

Use other name than Swift for the project. "Swift" is reserved.

I had this problem every few seconds in Xcode 6 Beta 3, and it continued even in completely new projects. I changed the Deployment Target from 8.0 to 7.1 and it has stopped.

Is your project named Swift? With seeing that message, build would be failed too(<unknown>:0: error: module name "Swift" is reserved for the standard library). Try using another project name such as SwiftTest. It would work.

In order to fix this you may have some weird issue with your Swift code. For instance having multiple defintions of IBOutlets because you were in the middle of copying and pasting. usually it is just a syntax error that couldnt be handled.

I found that by explicitly (statically) typing the variable types, rather than inferring them, solved the issue for me.

Quit Xcode if it's open. Then from Terminal run:
defaults delete com.apple.dt.Xcode
This will restore Xcode to the default settings. Open Xcode and everything should work again.

For me (xcode 6.1) reason was that I forgot to adopt my subclass to protocol.
For example this is wrong:
protocol SomeProtocol { ... }
class A :NSObject, SomeProtocol {
...
}
class B : A {
...
}
and this is ok:
protocol SomeProtocol { ... }
class A : NSObject, SomeProtocol {
...
}
class B : A, SomeProtocol {
...
}

A program consisting only of these two lines (possibly wrong in terms of Swift syntax) is enough to cause the "SourceKitService Terminated" error here:
var x = 42
println("Hello", x)
Using let instead of var makes the editor behave normally again. Xcode version 6.0 (6A215l)

Got same issue today, the thing was with println, I just tried the old NSLog style to print a value:
// something like this
println("value = %#", valueObj)
The way how we should compose strings in swift has evolved from printf style to inline style, so now you embed your values right into the format string like this:
"Here goes \(YOUR_VARIABLE)"
So, for the example above the solution is:
println("value =\(valueObj)")

I had same issue with Xcode6 beta 3 for a project created in beta 2.
It was because of new breaking changes in swift language i.e. array declaration syntax.
Check for the effected code due to breaking changes in beta 3.
http://adcdownload.apple.com//Developer_Tools/xcode_6_beta_3_lpw27r/xcode_6_beta_3_release_notes__.pdf
One of the example in my case was:
I had to change:
var tabBarController : UITabBarController = self.window?.rootViewController as UITabBarController;
to
var tabBarController : UITabBarController = self.window!.rootViewController as UITabBarController
Conclusion: Looks like if there is an error in source code, in some conditions this error is produced by Xcode.
Solution till the bug is fixed: Check for the error manually :)
Goodluck!

The solution for me happened to be changing the simulator. I was using iPhone 5S for my simulator and when I switched it to iPhone 5, everything worked perfectly. Hopefully a future version will fix it altogether.

I found that removing derived data from terminal resolves the issue until next crash. :S
It is located at: /Users/{User name}/Library/Developer/Xcode/DerivedData/{Project Name}-{Random char sequence}
I hope this helps.

I think I figured out one (as there are probably many) of the reasons this occurs.
In my case, I was importing Objective-C files through the Bridging Header that had one of the following true:
The implementation file (.m) for the Objective-C import, did not have the
app target properly set.
The Objective-C file only had a header (.h) file and NOT an
implementation (.m) file. (Again, I think this is part of the "no
proper app target" set, as you can only set targets in the .m files
and not the .h files)
Fixing the app targets on the Objective-C files OR removing the import of those file(s) in the Bridging Header all together seems to fix the issue.
FYI - If you need to set the target of Header (.h) files that have no Implementation (.m) file, you can follow these simple steps: Can't change target membership visibility in Xcode 4.5

Just to add one more potential solution here, I had accidentally named a class var the same name as it's type:
class var Settings:Settings {
get { return classVarWorkAround.settings }
}
This will crash SourceKit FOR SURE. Stupid syntax error, but in case anyone else makes the same mistake.
Edit: also according to #Portland Runner:
Similarly, If you set the return type to the func name you'll get the error.
func foo() ->foo{}

When this error starts popping up, just comment out the last/recent piece of code you wrote and wait for a while. The syntax highlighting should reappear. This is how I work around the problem.
func someFunc() -> (Int?, Int?, Int?) {
var retVal1:Int? = nil
var retVal2:Int? = nil
var retVal3:Int? = nil
//some other code
//commenting out the line below helped me
//(retVal1, retVal2, retVal3)
return (retVal1, retVal2, retVal3)
}

Reported to Apple (#17266321) :
Details:
Summary:
If we try to print a dictionary with value as an array a pop-up keeps on popping saying -"SourceKit terminated. Editor functionality temporaly limited". Xcode Freezes and looses context recognition causing text to be blackened.
Steps to Reproduce:
1. Create an array as - "var iOSHistoryArray = ["iOS6","iOS7","iOS8",]"
Create an dictionary as -"var MacOSYosemiteFeatures:Dictionary = ["Device":iOSHistoryArray]".
Print the dictionary as - "println("Dictionary containing Array value : %# \n",MacOSYosemiteFeatures)" (<<- Culprit-->>)
The step 3 causes the issue commenting which makes the Xcode functional again.
Expected Results:
Xcode should function normally.
Actual Results:
Xcode becomes nonfunctional, looses context recognition (All font is lost and all text becomes plain black), whole Xcode becomes Inactive.
Version:
Version 6.0 (6A215l)

Try It:
There is a bug in the Swift compiler / indexer. Some line or lines in
your code is giving it difficulty. You will have to edit your code
with some other text editor to comment out the offending line(s)
before you will be able to open that project with Xcode. If you have
no clue what the problem is, comment out all your code. Once you have
the project open, you can start bringing back code little by little
until the rise in CPU activity tells you that you've found the
problem.

Problem:
If there is an error in source code, the "SourceKitService Terminated" pop up may appear and code highlighting stops working. It may or may not happen, when it does its under multiple different conditions.
My case: Installed beta 3, OSX only project, one file detected the "half-closed range operator has been changed from .. to ..<" error. The pop up starts appearing and code highlighting starts failing.
Solution:
Fix error detected by Xcode
Change to a different .swift in Navigator, come back to the original
Syntax highlighting reappears and "SourceKitService Terminated" pop up is gone

In xcode, go to your menu bar >> window >> devices (shift+cmd+2) a new window will pop up, and on the bottom left, add a new simulator, specifically one running on iOS 8.0 to the existing list
edit: you might need to restart xcode
refrence:http://www.reddit.com/r/swift/comments/2bznfo/error_running_playground_unable_to_find_suitable/

In my case I had imported missing files in bridged header. After I deleted wrong imports the error notification gone.

I had the same error with the nested Objective-C++ project that now includes Framework with Swift code. In order to fix this issue I had to explicitly build the framework. Once I did that issue is gone, and doesn't come back ;)

Still happening with xcode 6 Version 6.0 (6A313)
Create a new project
Add a Framework & Library
Select cocoa touch framework
Add a Swift file
Add a class to the swift file
Crashes
ps: brand new mac mini, no previous xcode installs, nothing exotic. Just a beta product I suppose.

Xcode 6.1 Beta 3:
As soon as you define a non-private type alias (e.g. typealias Foo = Int) in one Swift file an type the letter c in another file the SourceKitService crashes.
Solution is either resign from using type aliases, wait for the next beta release or wrap your type aliases in class definitions:
public class DummyClass {
public typealias Foo = String
}
and use it like this:
var myVar:DummyClass.Foo?

Changing the deployment target to iOS 8.0 worked for me. I know someone said moving it to <=7.1 worked, but this problem seems to come in from multiple sources, so this alternative may work.

Related

Cannot find protocol declaration for *** in my 'MyApp-Swift.h'

I am working on a project that up to now, despite the mess, it was working ok. Today, believe it or not, I have been updating it to Swift 5.
The project has iOS and tvOS targets as well as frameworks, tests, and top selves extensions. The project also was started using Objective-C and over the years has become 90% Swift.
I am not sure at what point something went wrong but, when compiling, I get the following error for all my top self extensions (mostly all tvOS Targets).
I have found similar questions but I can't understand whats going on.
Any ideas?
You are probably missing an import StoreKit in the Swift files that define IAPHelper. Sometimes this gets imported transitively, and Swift doesn't necessarily need it, but the Swift bridging header does.
Ultimately you need to make sure there's an ObjC #import StoreKit; that is evaluated before this line of code.
First, I have to thank Rob for his tips. I wish he could get the points!
After troubleshooting with the tips provided:
Add StoreKit to your linked frameworks list. -> Didn't work
#import StoreKit; before #import <...-Swift.h> -> Showed error use of #import when modules are disabled
I also saw that "...-Swift.h" was only declared in the Build settings of my "...Topself" targets. Still quite unsure why as I would have thought the whole project still have ObjC dependencies... Still quite new to this challenge.
Furthermore, If I unfold the error I could see that there was some kind of error trying to find "...-Swift.h" file.
At this point, I remembered that I am using cocoapods (I don't like you, you don't like me relationship) and I hated to see the warning "...Overrides Enable modules (C - Objective-C)" so I set it to default for the whole project.
Turns out that that for all "...TopSelf" targets, the default value is NO.
By Overriding Enable modules (C - Objective-C) to YES, clean, and build, everything started working again.

Xcode 11 Beta 5 stuck indexing [duplicate]

A project I've been working for 2 months stopped working for no reason because Xcode got stucked on "Indexing". I can't Build the project anymore. If I try to build, Xcode freezes and I have to force quit. This happens only with this project.
I tried cleaning all derived data but didn't help.
I'm using Xcode 4.5.2.
Any ideas?
Open your Project Folder.
Find ProjectName.xcodeproj file.
Right-Click Copy and Paste to Safe Place.
Right-Click Show Package Contents.
Find project.xcworkspace file and delete that file.
Reopen Your Project and clean and Rebuild.
If your problem is not solved then replace the file with your backup file.
Close that project from Xcode
Open Xcode Organizer, find the problematic project
Delete Derived Data folder in the Organizer
Close/re-open Xcode
Nuking Derived Data is the first thing to try in all cases of Xcode misbehaving
I had this exact problem, it was caused by a 20 item array literal. Had to switch to different syntax. Pretty silly.
Close any opened Xcode
rm -rf ~/Library/Developer/Xcode/DerivedData
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder
Another thing to try if your trying to solve indexing issues and you're this far down the page!
Try adding this flag to your build settings.
-Xfrontend -warn-long-expression-type-checking=400
It will cause warning where the compiler take a long time to deduce a complex expression.
This may cause a build error which will go away after you find the slow expressions and then remove the build flag.
I had a similar problem, and found that I accidentally defined a class as its own subclass. I got no warning or error for this but the compiling got stuck.
class mainClass : mainClass
{
...
}
When using Xcode 6 and it says
Waiting for make
It might be that an instance of make is already running. Kill the process and indexing proceeds. Silly, but worked for me.
This happened to me. If you are using cocoapods do this:
Delete project.xcworkspace
Reinstall pods using pod install on the terminal
It will create a new project.xcworkspace
Open the new project.xcworkspace
-> Clean
-> Build
First, disconnect from network. Both your wired network and wireless network should turn off.
Second, kill the com.apple.dt.SourceKitService process. Then XCode would start to index again instead of stuck.
Hold alt > Product > Clean Build Folder
It's a Xcode bug (Xcode 8.2.1) and I've reported that to Apple, it will happen when you have a large dictionary literal or a nested dictionary literal. You have to break your dictionary to smaller parts and add them with append method until Apple fixes the bug.
For me completely closing out of Xcode and then restarting the project worked.
This is not the solution for the original question, I don't believe, but it is one more simple thing to try before deleting files and folders, etc. Credit to this answer for the idea.
I had a similar problem where Xcode would spend lots of time indexing and would frequently hang building the project, at which point I had to force-quit and relaunch Xcode. It was very annoying.
Then I noticed a warning in the project about improperly assigning self as a delegate. Sure enough, there was a missing protocol in the class declaration. Note that there is a similar assignment in the OP's sample code (though it is impossible to tell from the sample whether the correct protocol is declared):
leaderboardController.leaderboardDelegate == self;
After resolving that warning (by correctly declaring the implemented protocol), Xcode stopped misbehaving. Also, I should note that the project did execute correctly since the protocol methods were implemented. It was just that Xcode could not confirm that the protocol should in fact implemented by the class.
For me, I made a stupid mistake. I write a Class like this:
class A: A {
.......
}
A class inherit itself that causes the freezing. There is no message hint from Xcode.
Nothing worked for me, my project is too big (merging objective c, c++, swift, and java files with j2obj). I've disabled Xcode indexing and worked without code completion for months (and it's a pain). But finally I've found a workaround. The idea is to keep Xcode indexing the code, but to limit its CPU usage with an external tool like cputhrottle.
So first you need to install cputhrottle in terminal
brew install cputhrottle
Then limit the Xcode indexing process like this (20 = 20%)
sudo cputhrottle $(pgrep -f com.apple.dt.SKAgent) 20
I've exposed my "solution" here with mode details : How to prevent Xcode using 100% of CPU when indexing big projects
I'm working with Xcode 11.4.1 and I have the same problem with several projects. Every time, when internet connection is lost, indexing gets up. The best solution (it's just my opinion based on observing this problem):
- turn off internet and just kill the "com.apple...." process, then restart the Xcode(turn on connection)
or more easier
- just restart the Mac(with the internet)
Had similar problem in Xcode 6.4. The progress bar indicated that "Indexing" was "Paused". Tried deleting project.xcworkspace, then deleting Derived Data as described above. Did not appear to help. Noting that the posts above also suggest fixing warnings, and since I had inherited this huge project with 180 warnings, I said to myself, "What the hell this looks like a good day to fix warnings". As I was fixing warnings, a half hour later, I noticed that the "Indexing" progress bar had increased from 10% to about 20%. An hour later, it was at 50%, then another hour to 80%, then after another half hour it was done! Conclusion: Add "take a long lunch or a nap" to the above suggestions.
I experienced the same issue for Xcode 7.0 beta.
In my case, values for "Provisioning Profile" and "Product bundle identifier" of "Build Settings" differed between PROJECT and TARGETS.
I set the same values for them. And I also used the same values for TARGETS of "appName" and "appNameTest".
Then closed the project and reopened it.
That resolved my case.
In my case, deleting the derived data directory did not help. Apparently I had a file locked by another process, because after closing out a couple of terminal windows and emacs, and terminating a react-native packager process, everything resolved.
I have experienced this problem in some projects with Xcode 9.3.1 and in my case the problem is due to some swift code that for some reason Xcode doesn't like. This problem is hard to solve because is difficult to find what file is causing the problem.
When I have this problem, I removing some files from the Xcode project (removing references) and I try to test if indexing works. My process to do so
Remove some files
Close Xcode
Open Xcode
If indexing finish try to rename some method if works probably the files you have removed they have something strange for Xcode.
In my case I had a class definition with a reactive extension in the same file and for some reason Xcode doesn't like it, I moved the reactive extension to another file and now the indexing works fine.
2022 | Algorithm what to do:
Open activity monitor and kill there com.apple.dt.SKAgent
If did not help:
Close Xcode(cmd+Q). Run command in terminal:
rm -rf ~/Library/Developer/Xcode/DerivedData
If did not help:
Restart PC
If did not help:
Right click your PROJECT_NAME.xcworkspace, choose 'show content', and delete 'xcuserdata' folder
If did not help:
run your project build with additional warning. For doing this you need to write:
-Xfrontend -warn-long-expression-type-checking=100
to the following place:
and optimize code at all of places.
If did not help:
Z. Uninstall XCode and install it from scratch
If did not help:
Z+1. answer of El Belga https://stackoverflow.com/a/50541767/4423545
Also stop running app. if you have another application running with your xcode, stop it first and you should have your indexing continue.
For me, the cause was I opened the same file in both the Primary Editor and Assistant Editor at the same time. Once I closed Assistant Editor, it came through. (Xcode Version 7.2.1)
Close Your Xcode , close any git client(source tree or terminal)if it is opened and finally restart your project.
Faced this recently on XCode 7.3.1 - for me, I noticed RAM usage going to 100% on to CleanMyMac3. The problem magically fixed itself after I restarted my machine. In all fairness however, I'd already gone ahead and tried the accepted-answer, so you'll want to do the same before you restart just in case :-)
I fixed this by simply deleting the app from my device and rebuild.
I had the same issue in swift 2.2
It had to do with a generic function overloaded function
func warnLog() {
print("Warning line: \(#line) file: \(#file) ")
}
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
func warnLog<T>(input:T) -> T {
print("Warning line: \(#line) file: \(#file) ")
return input
}
all I needed to do is remove one of the non used overloads
func warnLog<T>(input:T? = nil) -> T? {
print("Warning line: \(#line) file: \(#file) ")
return input
}
My case: it was not the project.xcworkspace file, it was not the Derived Data folder.
I've wasted a lot of time. Worse, no error message. No clue on the part of Xcode. Absolutely lost.
Finally this function (with more than 10 parameters) is responsible.
func animationFrames(level: Float,
image: String,
frame0: String,
frame1: String,
frame2: String,
frame3: String,
frame4: String,
frame5: String,
frame6: String,
frame7: String,
frame8: String,
frame9: String,
frame10: String) {
}
To go crazy! The truth is that it is worrisome (because there is no syntax error, or any type)
For XCode 9.3 indexing issue - Uninstall the XCode and instal again from zero. Works for me.
This issue happened to me when my machine was out of swap space. Closed several programs and browser tabs and the build suddenly succeeded after 30 minutes of being stuck in place. Nothing to do with derived data, locked files, etc. on my side.

Xcode going crazy! while coding, loses classes, references and doesn't autocomplete giving often <<error type>>

After I installed the latest version of xcode i'm having a very annoying issue.
While I'm coding, xcode goes nuts. Without me doing anything weird, just typing code, xcode stop recognizing classes.
For example: I want to add UITableViewDelegate to my class, but it doesnt recognize it. After i type it manually sometimes it recognize it and it is shown in purple, some other time it doesnt. But both times it won't really consider it, so if I try to write down a method of that delegate, it won't show it.
Other times if I try to call a variable of a certain class, while trying to autocompleting it, it shows <>.
Other times if I try to call any class, let's say I try to type var test = UIActionSheet, it just shows a few elements in the autocomplete list (raw types, primitives, the classes of my main project, but it doesn't show the majority of classes).
It's like it's missing the documentation and the link with the main frameworks...
I'm working on a simple tabbed app from yesterday and it's the 3rd time i started all over because of this issue, thinking that starting over would fix the issue, but it's not working.
If i open a different project while the issue is going on, the other project works ( but i recoded all over my app so it's not that one the issue, and i also have the same issue on other project... it just doesn't affect 2 project at the same time )
i tried deleting derived data
i tried restarting both xcode and the comp
What's going on?
Here are two screenshoots where you can see what's happening:
I had the same problem earlier.
Exit Xcode and delete Derived Data folder here ~/Library/Developer/Xcode
Restart Xcode and you should see the autocomplete working again.
You have to learn how to take it apart and put back together.
Either reinstall Xcode, if it doesn't help, create a new project.
Then copy source files one by one and see when it breaks.
Freshly install the XCode IDE version 6.1
Use CMD + F to find all _element.
Check that if you named one variable _element
The following code may reproduce the error:
class _element:NSObject {
}
let _element:UIImage = UIImage()
// type _element under this line

Migrating issue from non ARC to ARC with XCode 5.0.2

I heard about ARC and I also used it with XCode 4.2 but now a days I have requirement to convert my non-ARC code to ARC format. I have followed some steps to for converting my code to ARC format but somehow i did not get success.
I followed below steps to convert code to ARC:
1. “Preferences” -> “General” -> check “continue building after error”. This step is fundamental to avoid an huge waste of time repeating the next steps every time an error is encountered!
2. “Edit” -> “Refactor” -> “Convert to Objective-C ARC”
3. “Select targets to convert” (check them)
4. Click “precheck” – “Cannot Convert to Objective-C ARC” (Xcode found N issues that prevent conversion from proceeding. Fix all ARC readiness issues and try again.) You will see this message at least once, because your code contains calls that are forbidden by ARC.
5. Fix them using suggestions (click on errors to open the popup containing the tip). Then repeat from step 1.
6. “Convert to automatic reference counting” window will appear (once issues have been fixed)
7. Click next
8. Review automatic changes
I still get errors in all HEADER files of my project regarding #property and #synthesize. I have to manually do all the changes in all HEADER files rather than it can be achieved by automatically just following above steps.
Please help me and let me know if you have any proper solution for this one.
Thanks,
Nilesh M. Prajapati
XCode could not fix those errors automatically. So you just have to fix them manually before moving on.

Xcode 4.5.1 get stuck when archiving

I just upgraded my xcode to version 4.5.1.
Everything worked fine before but now, when I Archive the project, xcode get stuck/hanging and never finishes the archiving.
In the status on top, the text says:
Compiling 10 of 10 source files...
Nothing happens after that. It is just stuck.
I can still compile and build the code (without archiving) and everything runs just fine in the simulator.
I have reinstalled xcode. The issue still happens after that.
Any suggestion will be appriciated.
More info:
I've pinpointed the problem to a specific line of code:CGRect tmpFrame3 = seeDetailsButton.frame;
I don't see any problem with this line...
Why would it work fine when building and running in the simulator but fail when archiving???
I figured out what is going on here.
First, it is not related to the archive process itself but to the build in Release mode.
The reason that I had the problem during archive is because then it builds in release mode.
About the issue itself:
It seems that there is some sort of an Apple compiler bug in xcode 4.5.1.
I'm using the Apple LLVM compiler 4.1. During compilation it has different optimization levels.
In Debug - the optimization is set to 'None' and is off. In release it is set to 'Fastest, Smallest [-Os]'. When I turn off the optimization in release mode (set it to 'None') - the issue does not happen.
More info:
After digging in my code, and trying to figure out what would cause a compiler bug during optimization, I saw that I had the following:
__weak ProfileButton *tmp = myButton;
Where ProfileButton is just a regular button inherits from UIButton.
When I remove the __weak everything works just fine. Even when I set the compiler optimization to 'Fastest, Smallest [-Os]'.
Recently faced this same issue, with Xcode hanging on the final file during compile. In the same fashion as the problem above, setting the optimization level for release to None ([-O0] to match the debug mode) would allow archive to run successfully.
However, for our code the specific bug was tied to a block that was capturing self. Per Apple's guidelines:
"If you need to capture self in a block, such as when defining a
callback block, it’s important to consider the memory management
implications.
Blocks maintain strong references to any captured objects, including
self, which means that it’s easy to end up with a strong reference
cycle..."
So be sure to check your code for this, if applicable, and follow Apple's best practice to capture a weak reference to self (example in documentation).
In my case I created a circlic subclass
It was like
#interface BaseTableViewController : PaymentTableViewController
and
#interface PaymentTabelViewController : BaseTableViewController
What i did was to reneme the last subclass, so it now looks like this:
#interface TopTableViewController : PaymentTableViewController
and
#interface PaymentTableViewController : BaseTableViewController
In my case the issue arose when one of source files contained a declaration of a very large array like this:
NSArray<NSArray<NSNumber *> *> *points =
#[
#[#38.576732f, #-90.230682f, #1495320246], // 1 item
...
#[#37.478034f, #-89.524851f, #1495336147] // 3000 item
];
There were about 3k items. Splitting the source line into small ones doesn't helped.
Fixed it by placing items in a CSV file and parsed it at run-time.
Another approach could be splitting into smaller arrays and concatenating at the run-time.

Resources