问题
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???
回答1:
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]'.
回答2:
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).
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/12944175/xcode-4-5-1-get-stuck-when-archiving