Hello, I'm sure this may have come up before. But I am currently a Windows user. I am interested in learning to program, as a hobby, if anything other comes from it bonus. I'm already old..lol.
But at the time a mac isn't in my budget, and so far what I can gather from here is possibly using WSL for swift is the better option than Windows natively, someone please correct me if I'm wrong.
Also if someone could point me to any learning resources that are not mac centric. There are a gazillion Udemy courses, but many seem outdated. Any guidance would be great.
I'm currently working on a cross-platform Swift course for higher education (but not assuming any prior programmming experience). The course itself is finished, but not yet published.
If you're interested in test driving it on Windows, feel free to DM me, and I'll hook you up with a free preview copy.
You can use the official Windows build by @compnerd and Visual Studio Code. No need for WSL.
When you feel comfortable about the Swift language and would like to program apps on iOS in future, you will find the Stanford CS193p course very helpful: https://cs193p.sites.stanford.edu/
If you have an Android phone or tablet that isn't really old (Android 7 or newer), you can install the Termux app and type pkg install swift to try Swift out on there. Combined with a bluetooth or USB keyboard, you can type out snippets from the Swift book @rayx linked.
My Android phone is my development "workstation:" this is pretty much what my desk looks like, except I use the phone as a touchpad and have a full USB keyboard instead. I regularly build large projects like the Swift toolchain on my Snapdragon 888 phone, takes a couple hours and works fine.
No, my phone is way overpowered for that, and I don't do any web dev.
Or are you going cray, cray, and compiling binaries on it?
Building the full Swift toolchain means building most of LLVM, which takes hours. The only drawback is that it rarely overheats when building such giant projects and is connected to an external monitor, as it has no fan.
So what are you building? Sorry for all the questions by the way, the setup fascinates me though. Do you just do backend with swift? Or are you using one of the cloud vms to build apps for mac/ios?
I was looking for a language that read easily- I'm big on syntax and avoiding line noise in my code, hence no Rust- had good native compilation, and boasted a decent-sized community behind it. I narrowed it down to Kotlin and Swift, and chose Swift because its native compilation was much more advanced than Kotlin/Native in early 2019.
Since these languages are all open source these days, I didn't expect much of a challenge and indeed was happy to find Swift had already been ported to Android by open-source contributors and I proceeded to fill in some remaining gaps.
@Finagolfin, is it possible to write "normal" UI android apps in swift only, or would that have to be a hybrid with Java/Kotlin host app, swift components and JNI in between?
I think if you want to use Android's built-in GUI, yes, some hybrid like that is the only option. However, since Android exposes OpenGL/Vulkan, you can use other GUI toolkits that target those renderers and support touch, which is what flowkey apears to be doing with their Android app written in Swift.
i see, like flutter, not fond if this approach. i wonder what's the ultimate underlying limitation... is it possible to create swift -> kotlin/java interop similar to how swift -> Obj-C is done? or is it even theoretically impossible because of garbage collection vs ARC differences?
Well, the most immediate limitation is the Android GUI is not exposed to C or C++, despite likely being written in those languages for performance. google wants you to use Java or Kotlin, not even C or C++, so it doesn't provide public C/C++ GUI toolkit APIs (I suppose you could call the private APIs anyway, but that may not be stable). I'm not familiar with the tighter GC/ARC integration issues that might come up, and I've said it's not worth pushing for that for me.
C or C++ is not essential, Apple UI frameworks also don't expose C or C++ accessible API. swift interop with Obj-C which allows it to work with UIKit, etc. it's not immediately obvious why a similar interop can't be done between swift and Java (with enough effort), so one can write:
public class MainActivity: Activity {
public override func onCreate(_ bundle: Bundle) {
super.onCreate(bundle)
let label = TextView(self)
label.setText("Hello world!")
setContentView(label)
}
}
things to solve would be:
ARC vs garbage collection (xamarin solved this somehow).
swift C interop. non GC language like C would cause problems in this hypothetical "swift/Java" environment. to not deal with JNI - C interop can be thrown away in such environment.
JVM vs LLVM differences.
given relatively small syntax differences between Swift and Kotlin another option could be Swift to Kotlin preprocessor.
Use existing methods like JNI or some serialization option like protobuffers: people are doing this today, such as in that large Android thread I linked you.
Compile Swift natively as it is today but come up with some new interface to call Java methods from Swift. Not sure this would be possible to do purely on the Swift side though, may require Java changes too, which google may not provide.
Translate Swift to run on the JVM, whether through Max's idea of compiling Swift to JVM bytecode in that Android thread, or your "Swift to Kotlin preprocessor" idea.
The latter two integrate the languages more tightly, so you get greater performance, at the cost of more work getting the two language runtimes seamlessly working together.
I'm fine with the first option, ie the status quo, as I don't have some giant Java codebase I need to tightly integrate with.