Issue converting from Swift 2 to Swift 3 in Xcode 8 - ios

So I updated to Xcode 8 and when prompted to convert my source code to Swift 3 I said yes. I forget what I did after that, but for some reason my code is back to the way it was. Now when I try to convert it again, Xcode tells me that i already converted it so I cannot do it again. Is there any way to reset this convert feature or trick it to convert again?

There is no way if you are not using version control.
Follow this link (
How to Convert my Swift Code back to 2.3 ) for better understanding.

For anyone that is interested I found a workaround. First, create a new project and then copy your source code file(s) into it. Second, hit Edit -> Convert -> To Current Syntax. At that point either stay within the new project or copy your code back to your original project.

Related

Convert Old Xcode Project to New

Let's say I found some source code from 3 years ago but now it doesn't run right due to xcode changes. Is there an easy and quick way to convert an old xcode project to work with the newest xcode?
There is no definite simple way to always correctly uplift an old codebase.
It depends if it's ObjC or Swift.
It depends which version of Xcode you're moving to.
It depends on the libraries the project links against.
etc etc etc.
If you edit your question to be more specific you will get more help.

Is there a way to turn off Xcode 8's autocomplete for image names?

Xcode 8 has this new feature that is supposed to suggest image file names when you use UIImage(named:)
In my case it suggests image names even when it doesn't make any sense.
Example:
There is nothing in preferences. I wonder if there is some secret command to disable this part of autocompletion.
No this unfortunately can't be turned off, and nothing states that this is fixed in the Xcode 8.1 Release Notes.
It should either be fixed or you should have the opportunity to turn it off. The functionality is kind of good when it´s used for it´s purpose only, as I describe in this post.
But the issue is that Xcode 8 is inserting images inline in source when it can't possibly make any sense as you mention. For example, if you have a for iteration and type for x in to start a loop and you have any image in the project whose name matches "in" using this syntax.
Annoying issue, that I hope Apple will fix soon, because the feature is good when it´s used for images only.
Update:
Just confirmed that this is still an issue in Xcode 8.1 stable version.
Update:
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Update
This seems to be fixed in Xcode 10 now.
It seems to me that the best way to deal with this issue is by using comments (commmand + /). Changing the code to become a comment seems to turn off the autocomplete for image names.
So, you would have basically to switch back and forth between commenting and uncommenting your code (e.g. you find an error, make your code as a comment, fix the error, uncomment your code, check if your changes fixed the issue, and so on.).
Example of the same code with and without being a comment.
Simply update to Xcode 10: the image autocompletion feature has been discontinued:
Code Completion for Swift image literals has been removed in Xcode 10. (38087260)
Source: the Xcode 10 Beta release notes (this note was removed in the final release notes)

Xcode 8 Image Completion

In Xcode 8, you have images autocompleted while typing.
Question is : Why?
I tried to init UIImage with the suggested result, but it doesn't work.
Does anyone know how to use it ?
Xcode 8 will automatically recognize any images you’ve got in an Asset Catalog and offer them up as a suggestion inside of a UIImage initializer.
So basically what you need to do is just the following (as you have done in your question, but there must be something else that´s disturbing it):
let i = voiture // image name
And then just use i when you want to set an image.
Under the hood it’s creating code that looks like this: #imageLiteral(resourceName: "voiture.png"). But inline in the source editor, you’ll just see the file name of the image. The #imageLiteral syntax is only recognised on Swift 3 or later.
Here is a demonstration video link where I do this and here is a link to a sample project that I created.
Note that you need to click on the instellisense suggestion so that you see a thumbnail of the image in the code and then the image name.
Update 1
This functionality remains in Xcode Version 9.0 beta 6 (9M214v)
Update 2
Xcode 11.2.1, this is not appearing anymore.
An image literal already is a UIImage, you don't need to pass it to a UIImage to initialize one.
I'm unable to find an "official" source for it, but from my personal testing it appears that while the autocomplete works in both Swift 2.3 and Swift 3.0 projects, image literals will only work correctly in a Swift 3 project.
Give it a try in a Swift 3 playground and you'll find it works just fine.
I have been using this feature. Basically if I have an image that begins with "ic", I would type let i = followed by ic. At this point, Xcode 8 will show a dropdown of images and I then choose the correct image from the list. I have never bothered to actually type UIImage(. It works just like autocompleting code except that it uses the filename of the image.
In your case, there is probably some other issue causing the compilation to fail.

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.

Resources