Migrating issue from non ARC to ARC with XCode 5.0.2 - ios

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.

Related

Xcode 9 Compiler Hangs On File With No Warnings Or Errors

Background:
Attempting to upgrade large 100k codebase from Swift 2.3 to Swift 4. Was making good progress, fixed ~1000 error. Then, after changing one of our DTO objects to use Any instead of AnyObject (because we had to), the compiler started hanging.
Problem:
When compiling the application will get to a certain file and just get stuck (even after 24 hours). It is not frozen just stuck compiling. I have tried temp removing the file but then it just gets stuck on another file and so on and so on.
Research & Attempts
I've read up on the compiler and how to turn on warnings and flags. I tried looking at -Xfrontend -debug-time-function-bodies and -Xfrontend Xfrontend -warn-long-expression-type-checking but nothing comes up. When I look at the build transcript for the file its stuck on there is no info in the expanded transcript.
Do you know what else I can check? I suspect it has something to do with its inability to infer type given how many Any filled dictionaries we have but without getting better information I have no clue where to go from here.
Do you know how I can get info as to why it's getting stuck on this file and no warnings given?
To followup, it took several days, but by first converting to Swift 3.2 and then Swift 4 (commenting out most code to solve later) I was able to get it to compile in Xcode 9.

Xcode 8.3 Indexing & Building Extremely Slow

I am posting this after reading many similar posts on here regarding this issue and none of the solutions that worked for other people not working...
Xcode Version 8.3.3 (8E3004b)
Swift 3.1
Things I tried
Deleting Derived Data folder
Deleting Workspace File
Cleaning Build Folder
Cleaning Build
Reinstalled Xcode (after complete removal)
I also looked for Swift Issues:
Removed all concatenating strings
Cleaned up Swift arrays and dictionaries
Added Whole module optimizations
This all started happening after last Xcode update of 8.3.3. My project was compiling within seconds and now I have to wait at least 15 mins for it to index, then 5 minutes to compile after everything I change even something small in code.
When Building, it get stuck in "Compiling Swift source files". Is there way for me to look in to where it is actually getting stuck?
BIG UPDATE
I tried pretty much everything. Read every article, post, ect. NOTHING worked. My project was created right after 10.0.
Solution
Creating a new project and copying each file worked! It used to take 8-9 minuted to build. Now less than 2 seconds!
Apple knows about this problem, and says that Xcode 9 beta will perform much better. Note that if you don't want to update to Swift 4, you can continue compiling in Swift 3 mode using Xcode 9. The big limitation is that you won't be able to submit your project to the App Store until Xcode 9 goes final.
Also, Xcode 9 contains a new build system. You don't get it by default: you have to turn it on for this project. Choose File > Project Settings and switch the pop-up menu to New Build System (Preview). This is experimental, but it will be the default build system eventually, so it would be interesting to know whether this makes an appreciable difference.
If you don't want to update to Xcode 9 beta, you will just have to do a binary search: comment out all your code and start adding it back, piece by piece, until you find that piece that's causing the trouble.
The best way to work this out is to find what out what the build is doing while compiling your code. This is a really useful tool to use: https://github.com/RobertGummesson/BuildTimeAnalyzer-for-Xcode
When you run this tool it will show you what methods are taking the longest to compile, and then you fix those. Once you have done that, you can also try the answer I gave here to decrease the build times: Extremely long compilation times with Swift in Xcode

SourceKitService Terminated

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.

IOS arc disabling for part of code [duplicate]

This question already has answers here:
How can I disable ARC for a single file in a project?
(18 answers)
Closed 9 years ago.
I'm a newbie to IOS technology. I have been developing an app, in which I have to add around 10,000 mkannotations to my map. So I prefer to use clustering algorithm (probably using k_means). However, I found this beautiful external library at (https://www.cocoacontrols.com/controls/adclustermapview)
When I complied the example framework of this project and ran it on simulator everything works fine, however, when I add the required files to my project as they described, it raises a lots of errors regarding
retain
release etc.
So I understand there is some issue with the arc compatibility in the project
Here are my questions
These retain, release methods being used in some project, does
that mean that they are developed with old versions of IOS?
If so, how do I resolve these error, other than manually removing them?
Is there a method in IOS, which allows me to compile a code
partially using one compiler and the remaining using other?
Select desired files at Target/Build Phases/Compile Sources in Xcode
PRESS ENTER
Type -fno-objc-arc
Press Enter or Done
In xcode Edit-Refactor-Convert to Objective-C ARC select your app then check button.Finally click save button.
These retain, release methods being used in some project, does that
mean that they are developed with old versions of IOS? NO
If so, how do I resolve these error, other than manually removing
them?
Is there a method in IOS, which allows me to compile a code
partially using one compiler and the remaining using other? You can disable ARC for some files.
This problem might be coming because you must be using ARC in your project while this framework is not. To remove ARC for particular classes go to Targets, then build phases tab, under the compile sources group add '-fno-objc-arc' as the compiler flag. This will make sure that ARC is skipped while compiling this class..

How to automatically convert Manual Retain-Release code to ARC?

I have thousands of line of code written for iOS 4. The codebase contains many calls to retain and release, which cause errors when the project is updated to iOS 5 and ARC.
Is there a way to automatically convert Manual Retain-Release (MRR) code to Automatic Reference Counting (ARC)?
From the Xcode 4.2 release notes:
To initiate the process, enable Continue building after errors in the
General Preferences pane, then choose Edit > Refactor > Convert to
Objective-C ARC. The targets that you convert are updated to build
using the Apple LLVM compiler. Xcode attempts to build your target and
to determine what changes must be made to use ARC. If it finds any
issues that prevent conversion, Xcode displays a dialog directing you
to review the errors in the Issue navigator. After you correct the
errors, choose the Convert to Objective-C Automatic Reference Counting
menu item again to restart the ARC-conversion workflow.
In Xcode 6+, the command is now:
Edit > Convert > To Objective-C ARC...

Resources