Conversion from Swift 3.0 to 4 - swift

How can I convert my code that I wrote a few years ago to Swift 4.0 without using XCode 10.1? Is there any way to run it on some online simulator or on the newest version of XCode? This is some code that I wrote for messing around and seeing what features the touchbar has. I get this message when I'm trying to open the project.

I'm not aware of any automatic migration tools other than the one that Apple provides in some versions of Xcode. I think your choices here are:
Use migration assistant in Xcode 10.1 (which is still available from developer.apple.com) to update the code more or less automatically.
Rewrite the code yourself.
If it's just code for experimenting with the Touch Bar, why not migrate it yourself? There are lots of resources to help you figure out what you need to change. While you're at it, you might as well move all the way to Swift 5.7 -- you'll be modernizing both your code and your knowledge of Swift.

Related

objc[29733]: Swift class extensions and categories on Swift classes are not allowed to have +load methods xcode 10.2 running on ios 12.2

I updated my Xcode to Version 10.2 (10E125) and my existing swift project crashes with "objc[29733]: Swift class extensions and categories on Swift classes are not allowed to have +load methods" while running in iPhoneX simulator 12.2
Apparently in iOS 12.2 you can't use anymore + (void) load.
You should refactor your code to use __attribute__ instead of + (void) load.
The old answer was given incorrectly but has good talk material to understand the problem.
I ask to any Developer to give a better answer that this one. I reckon my lack of knowledge is a speed bump on this answer but my idea is to at least start giving some insight on how to solve it!
If at least one developer can make is code work, my job here is done :)
===============================Old Answer==================================
It's a known bug.
It seems the new 12.2 don't allow some method's to load swift modules.
A Fix was already made, let's hope it enters the react native 59.3. (Fingers Crossed.)
For more information:
https://github.com/facebook/react-native/issues/24139
There are some temporary work arounds pls check the link above.
=============================EDIT old answer===============================
react-native 59.3 was released a few moments ago with this bug fixed, pls update.
For anyone encountering this error in a React Native project with Xcode 10.2, check that you are using version 0.59.3 or later of react-native, which includes a fix for this issue, which is related to using RCT_EXTERN_MODULE for Swift classes.
This issue was due to incompatible version of pod library for Xcode 10.2. Solved by updating all the library with version compatible to Xcode 10.2.

Why Swift versions are so tightly coupled with XCode versions?

Sorry if this has already been asked, but would like to understand in detail as it has created huge dependencies on all my Swift apps.
With most of the Swift version updates there is Xcode version which is tightly coupled with it.
For example if I create a framework with Swift 4.0.3 using Xcode 9.2, it does not compile with Xcode 9.3/9.4 or upcoming Xcode 10, which I understand as Swift itself is evolving and no complier can provide forward compatibility.
But would like to know any one of you treat this problem in different way is there some short route that I am completely missing.
This situation will get a lot better after we reach Swift 5. Until then, all you can do is live with it, updating every time you update to a new version of Swift. Two suggestions:
Your life is made a little easier in recent Swift versions because you can use conditional compilation with #if and a condition like swift(>=4.2) or (starting in Swift 4.2) compiler(>=4.2), so that you can talk different ways depend what version of Swift we're compiling under.
Language version is a build setting, per target. So the coupling is not completely tight; if you're using older code, you can continue (to some extent) to use an older version of the language. This screen shot is from Xcode 10, showing that you can compile Swift 4.0 code:
This is not necessarily an answer of sorts, but you do have the ability to work with varying Swift versions in newer (see this answer for more detail). My approach has always been to keep up to date with the latest Xcode releases, be them via the Mac App Store or Developer Downloads, and run a copy of my project to determine what changes are coming.
The changes between earlier versions of Swift (1.0 -> 2.0) were incredibly jarring. The changes from Swift 4.0.3 -> 4.1 (or even 4.2) are not as drastic, and while still critical to the development of the language, Xcode now does a far better job of suggesting how to update your code.
In short, there is not necessarily a short route (that I'm aware of), but you may find yourself in a better position by constantly evaluating your current code in newer Xcode versions and deciding how and when to make the move to the newer language.

Is there a way to avoid converting Swift from 2.2 to 2.3 or 3 using Xcode 8?

I upgraded the Xcode's version to Xcode 8.0, the error that I'm getting is that it forces me to convert the syntax, before the update I'd 2.2 version, but now it requires the version 2.3 or 3.0, and when I try to convert with the Xcode converter, it breaks the entire project (too many errors, and the converter commits lot of mistakes).
Is there a way to use the 2.2 version without upgrading ?
With Xcode 8 you can upgrade to Swift 2.3 and very nearly everything will stay the same. Your project shouldn't break and your changes should be minimal.
You'll need to go into the target's build settings and set the option Use Legacy Swift Language Version to Yes, which will allow you to keep compiling Swift 2.3
Note that the Xcode parser will complain while indexing about various things that aren't Swift 3 compatible, but the warnings will go away once you build successfully.
If you already have upgraded to Xcode 8, it will always ask you to convert to either Swift2.3 or Swift3
#par above shown you how you can just keep compiling on Swift 2.3 using the Use Legacy Swift Language and likes what others comments on your question, you will have to upgrade it sooner than later.
However, to answer your question of avoid the converting to Swift2.3 or Swift3. The way I am using is download the old Xcode7.3.1. You can look for the download here. Do not replace your Xcode8 but just maybe drag it onto desktop or another directory.
I have some project that depend on other libraries and also previous client project. Therefore I found that using Xcode7.3.1 to open such project is easier and more convenient.

How to stop swift syntax updates in Xcode?

Is there any way to stop Swift syntax updates for Xcode? The errors are quite difficult to figure out and existing projects fail to run the apps. Thanks.
If you open the project in the latest xcode 7. It will automatically ask you whether you want to update the syntax or not.
Hope this helps.
Xcode only ships with the latest Swift version. You will need to upgrade your Swift code or stay with an older version of Xcode.

Targeting iOS version, and which features will be available

I am learning iOS development. And I had couple of questions, hope people don't mind
answering them here.
I was reading a chapter about ARC in a book. It seems nice. I've heard it is for iOS 5. Now, my question is, if I want my app to be available for iOS4 - does it mean I can't use ARC? (that would be a shame).
Also, I am not sure yet, for which version of iOS I should target my app. How is this reflected on my code? For example, I suppose if I target iOS5 I can't use features of iOS6 right? But if I target iOS6, then my app won't run on iOS4?
Any tips in this direction appreciated.
I agree with David's comment and you should concentrate on iOS 6, but for information and future you would construct your app using a combination of weak linking and respondsToSelector: so that your app can use features of newer versions of iOS but still be compatible with older versions.
NO Arc can be only for iOS 5 or later but if you want your older code to be ARC enabled then you can Refactor->convert to ARC for that file. Also if you want your code to be Arc disabled then for each file you can write down "-fno-objc-arc" in build settings.
Ya new features wont be compatible for your older versions. So make sure you should be very specific for your requirements. The requirements of your App will make you conclude which iOS version you should target.
Hope this helps :)
You can make individual file non-arc as per your requirement in Project.
It is very simple way to make individual file non-arc.
Follow below steps :
Disable ARC on individual file:
Select desired files at Target/Build Phases/Compile Sources in Xcode
Select .m file which you want make it NON-ARC
PRESS ENTER
Type **-fno-objc-arc**
you can use ARC in ios 5 and above but not in IOS4.
If you targeting your app to IOS 5 then you will be able to use ARC as well. If u target it to iOS 5 then it will work on IOS 6 as well (only the deprecated features wont work on iOS 6).