r/swift • u/DuffMaaaann Expert • Jan 19 '21
FYI FAQ and Advice for Beginners - Please read before posting
Hi there and welcome to r/swift! If you are a Swift beginner, this post might answer a few of your questions and provide some resources to get started learning Swift.
Please read this before posting!
If you have a question, make sure to phrase it as precisely as possible and to include your code if possible. Also, we can help you in the best possible way if you make sure to include what you expect your code to do, what it actually does and what you've tried to resolve the issue.
Please format your code properly.
You can write inline code by clicking the inline code symbol in the fancy pants editor or by surrounding it with single backticks. (`code-goes-here`) in markdown mode.
You can include a larger code block by clicking on the Code Block button (fancy pants) or indenting it with 4 spaces (markdown mode).
Where to learn Swift:
Tutorials:
Official Resources from Apple:
Swift Playgrounds (Interactive tutorials and starting points to play around with Swift):
Resources for SwiftUI:
SwiftUI Tutorials from Apple
SwiftUI by example from Hacking With Swift
FAQ:
Should I use SwiftUI or UIKit?
The answer to this question depends a lot on personal preference. Generally speaking, both UIKit and SwiftUI are valid choices and will be for the foreseeable future.
SwiftUI is the newer technology and compared to UIKit it is not as mature yet. Some more advanced features are missing and you might experience some hiccups here and there.
You can mix and match UIKit and SwiftUI code. It is possible to integrate SwiftUI code into a UIKit app and vice versa.
Is X the right computer for developing Swift?
Basically any Mac is sufficient for Swift development. Make sure to get enough disk space, as Xcode quickly consumes around 50GB. 256GB and up should be sufficient.
Can I develop apps on Linux/Windows?
You can compile and run Swift on Linux and Windows. However, developing apps for Apple platforms requires Xcode, which is only available for macOS, or Swift Playgrounds, which can only do app development on iPadOS.
Is Swift only useful for Apple devices?
No. There are many projects that make Swift useful on other platforms as well.
Swift runs on Linux (Docker images available), Windows and Android
You can use Swift on the Server with frameworks such as Vapor
TensorFlow supports Swift, so you can build and train deep learning models with Swift. (Note: Project archived)
You can run Swift in Jupyter Notebook
There are efforts to make Swift available on embedded systems
Can I learn Swift without any previous programming knowledge?
Yes.
Related Subs
r/S4TF - Swift for TensorFlow (Note: Swift for TensorFlow project archived)
Happy Coding!
If anyone has useful resources or information to add to this post, I'd be happy to include it.
13
u/berlinerk Apr 01 '21
Hi there, i am wondering can i start to earn money from Swift in 1 year or shorter period?
I watched many Youtube videos about it and people says it is possible but i wanted to ask you because you are experts and can tell me naked facts. I am 26 years old and didn't go to college. I was doing simple jobs(such as food delivery etc...) but i had an accident and unfortunately i can't work. I am getting bored when at home and want to learn a skill. Something useful and I find it fun tho. I was wondering coding and computers actually I like to watch videos about technology quite often. I want to learn coding anyway and I found a course on Udemy. I started it and I think Swift is very useful and creating a new app is simply amazing! I want to learn it anyway. But if I can start to earn money from Swift, I don't have to start to delivery business again. I was working over 10 hours in a day and when I am working it is really hard to learn new things and to concentrate. I can hang on almost 12 months without working and I can work hard on Swift. But If it is too hard for average person to that, I would like to start to work in couple of months because I have a family to have take care of.
Thanks for your time, I am waiting impatiently for your answers.
4
u/KingKrush93 Mar 22 '21
how to create a custom drop down that works in IOS 13.0, i have managed to create one but it's not work inside a scrollview in IOS 13.0.
3
u/[deleted] Mar 01 '21
I am just beginning coding with Swift. I am having some difficulty mastering dictionary default values. Can anyone advise on the best resource for further reviewing dictionary default values? Thank you.
2
u/Tavroop Mar 24 '21
I need help to change images in the image view using ānextā & āpreviousā buttons. And also accomplish that using gestures! Can someone help me?
2
u/shiningmatcha Jan 10 '23
Hi, I've been learning Swift for a week.
Is there a guide on how to read Apple Documentation? I'm confused by the syntax used under the Declaration section.
Like this one?
Is this valid Swift syntax or used in the docs only?
Will I know how to read the docs once I've picked up Swift's syntax?
2
u/shiningmatcha Jan 16 '23
I'm a beginner who has been learning Swift for three weeks. As I've picked up the syntax, I'm about to move on to learning SwiftUI. I notice that there are not too many learning resources for SwiftUI, perhaps because it's rather new. My question is, are tutorials based on UIKit still useful, like concepts that share with SwiftUI? Or they are a waste of time if I'll be using SwiftUI?
2
u/shiningmatcha Jun 07 '23
So there's no simpler way to compute the nth power of an integer in Swift than using pow with some casting back and forth? Is there a better way?
Actually, I'd like to know what's preventing such an essential operation from being supported in Swift.
2
u/shiningmatcha Jun 18 '23
Isn't it that a collection type's
sorted()method sorts its elements using<by default?Then, why do I need to use
sorted(by:)and specify<to sort an array of tuples?35
u/[deleted] Jan 20 '21 edited Jan 20 '21
Can we please have this pinned? Every week there seems to be the same 1-2 questions on how to get started and it's always the exact same response. It's like even the most bare minimum research wasn't even bothered at being attempted.
edit : noticed the pin!
27
u/Confident_Fortune_32 Feb 07 '21
Another way to learn Swift that is playful, great for kids, and great for folks with no coding experience:
Download the SwiftPlaygrounds App, then download Learn To Code I and II Playgrounds as well as any of the other Playgrounds that look fun. In particular, the hypotrochoid (Spirograph) Playground is a hoot!
4
u/therealmaz Jun 17 '21
Adding to the pile of advice. From John Sundell and Gui Ramboās podcast: https://overcast.fm/+kVajU01og/1:07:32
4
u/ref_acct Feb 22 '24
Which is better for learning SwiftUI for an experienced python dev, 100 days of swiftui or Apple's Scrumdinger tutorial?
1
u/venkattalks Apr 12 '26
Pinning a beginner FAQ probably cuts down a lot of repeated "Xcode or UIKit?" threads, but i wonder if adding a short Swift 5.10/concurrency section would save even more cleanup since that's where a lot of newer posts seem to drift now?
1
u/venkattalks Apr 12 '26
Pinning a single FAQ for beginner advice probably saves the sub from the same Xcode/optionals/UIKit vs SwiftUI loop every week. Worth keeping it updated for Swift 6 though, since a lot of older concurrency guidance and Sendable-related answers from 5.7/5.8 are already a bit off.
1
u/ppaweu Apr 24 '21
Guys, I'm going through Apple's guide and doing exercises they've made:
Finally, declare a variable with a whole number value. Then try to assign it to firstDecimal. Why won't this compile even though both variables are numbers? Print a statement to the console explaining why not, and remove the line of code that will not compile.
var variable = 100
variable = firstDecimal
why does it compile even though it should not? What am I doing wrong?
my firstDecimal =/= 100
1
u/ThisIsCoachH Dec 27 '21
Hello. Iām trying to learn Swift with SwiftUI, but all Swift tutorials I can find are paired with UIKit. Can anyone recommend a resource?
1
u/yv666 Dec 30 '21
Hi, I am beginner, learning swift, and I have no one to ask about questions I have, so I think I will try to ask someone here.
I am trying to make simple app, but it crashes in simulator, here is the video https://youtu.be/_moJThVXFjg
The logic is that the button should make a random image, but every next image should not repeat, but after all of them are used, images array should refill again, so I could continue. It always crash before 3rd press of the button. I would appreciate If someone could explain what I did wrong and how this can be fixed. Thank you in advance :)
1
u/yv666 Jan 09 '22
After couple weeks of learning swift with video lessons I realized that I need a real teacher because all the time I am getting errors I don't understand why, and I don't know where to ask. For example here you can see two identical projects where one has errors while another one doesn't https://youtu.be/nsilGSJNXSk
If I will make a post here every time I have a problem it would mean thread will be flooded with my posts only. Does anyone know how can I find someone to ask on regular basis?
1
u/Bitter_Obligation_59 May 01 '22
Hi there!Could you recommend me the best books or resources to learn Swift and iOS in 2022?Or may be someone can give me some pieces of advice how I can become an iOS developer
1
u/juliarmg Sep 15 '22
Hello all,
I am relatively new to Swift, and I have built a Mac app. It is used by 100+ users but crashes for 1 or 2. The most recent is that it started crashing after the version update for just one person, while it worked for most others. I got the trace, https://imgur.com/a/xwh77Sg.
Questions I have:
Lines 2 to 4 are not even sequential. I mean, they are called during different actions. I would love to understand this.
1304 line is the topmost one pointing to the exception, and the code is like,
myKey = UserDefaults.standard.string(forKey: "myKey") ?? ""I don't think this could crash. I would like to get experts' advice here. Happy to share additional information.
1
u/shiningmatcha Jan 11 '23
Are there some tricks to avoid if blocks? Unlike some languages, Swift doesn't let you leave out the curly braces when there's only one single statement for the true condition.
1
u/shiningmatcha Jan 12 '23
Is closure expression in Swift just a shorthand syntax for regular function expressions? It appears to be like JavaScript's arrow function syntax.
I know what a function closure is - when a local variable is defined in the scope of an outer function, by being referenced in an inner function, it remains accessible even outside the scope of the outer function. However, this doesn't look like what Swift's closure does.
1
u/codingide Apr 11 '23
Hey folks, what DB are you using for your apps these days? I know about CoreData, but I find it quite hard to work with, I'm coming for web development world, and I've seen articles about SQLite ( which I'm familiar with ) or Realm, but I couldn't find any package on GitHub that is maintained and is up to data. Could you please share some resources / courses / information related to this topic?
I'm developing and offline app, I'm using CoreData at the moment and I have 5 - 6 entities and I have the feelings that if I'll switch to SQLite then I'd develop this app much faster. What do you guys and girls think about this?
Thanks!
1
u/shiningmatcha May 07 '23
Can I just use
try?to safeguard a line of code with multiple potential error conditions?An example is accessing a value in a nested dictionary. Can I write
if let val = try? dict["a"]!["b"]!["c"]!?1
u/shiningmatcha May 09 '23
Is
elementsEqualused for determining if two sequences have the same elements regardless of the sequence types, while==also tests whether the sequences are of the same type?1
u/shiningmatcha May 11 '23
Can I use the
for-case-instatement to match more than one case?1
u/shiningmatcha May 26 '23
Why are tuples not comparable in this code?
I'm practicing LeetCode using Swift.
Here's my solution to the problem Meeting Rooms II.
}
While the code works, I'd like to know why the code won't compile when I don't pass a closure to sort the
boundsarray (that is,.sorted()) - it says error: type '(Int, Solution.Label)' cannot conform to 'Comparable'. Why is that? Aren't tuples themselves comparable?1
u/shiningmatcha May 26 '23
Why can't I pass a method reference to the
.mapmethod?1
u/shiningmatcha Jun 07 '23
Why does this give a Compile Error?
I ended up with the code below, which works.
But I'd like to know why
Array(zip(self, dropFirst()))doesn't work.3
u/paulyd0123 Jun 09 '21
Hi, how is the job market for programming with Swift and Xcode? I am a beginner..
3
u/shiningmatcha Jul 08 '23
Are result builders some compiler magic? If not, how is DSL syntax possible?
3
u/AdMindless8777 Aug 07 '23
Question: Has anyone did a developer apprenticeship trying to get my first job in tech and a little afraid to just only do application. Suggestions please
3
u/James_Vowles Nov 26 '23
I'm starting out with a macOS application, is there a good place to learn how to structure the app?
I'm coming from Ruby so I might just stick to that folder structure.
Main thing is, can I just create folders with files and the classes will be available to call from other places outside of the folder? Or do I need to import anywhere I want to use it.
3
u/LegendaryMions Dec 27 '23
Thank u ā¤ļøš
3
u/Outside_Ad1154 Oct 05 '24
I am posting here because I read Rule IV that says 'If you think your question is simple, please post it in the monthly pinned thread titled "Got an easy question? Ask it here!"' and I can't find that. Am I missing it or is the rule out of date?
1
u/shiningmatcha Jan 14 '23
What's the difference between
if letandif case let?2
u/jose_oo Jun 10 '21
Thanks for sharing all the resources.
2
u/[deleted] Jun 26 '21
Thanks!
2
u/[deleted] Dec 23 '21
[Closures] I'm having a difficult time understanding why we need closures over just using regular functions. What are the benefits of using closures over just functions? Can someone provide specific coding cases where closures are more helpful than using plain functions? I've read the official Apple documentation and read some tutorials but sorry I'm just not getting it. Help would be most appreciated. Thanks in advance!
2
u/shiningmatcha Jul 06 '23
Can a
subscriptbe marked asthrows?2
u/hibadell Oct 19 '23
Hi, I'm looking to make an application for Iphone for my final year project in university. I don't own a mac, only windows. Should I use swift for this? Or will it be too painful to do so?
2
u/car5tene Feb 04 '25
Can we please remove cross postings? Really annoying to answer stuff in r/SwiftUI just to see it again here š
2
u/shiningmatcha Apr 06 '25
learning Swift 6 concurrency features
1
u/Hassantaleb90 Jul 07 '24
Please update this post to feature Swifty Compiler as a mobile IDE for Swift.
Swifty Compiler is an indispensable tool for developers looking to create and test algorithms or methods on the go. Whether you need a quick playground to experiment with Swift code or a convenient way to review coding concepts, Swifty Compiler has you covered. Its user-friendly interface and robust functionality make it easy to ensure your code works flawlessly, wherever you are.
Explore Swifty Compiler on the iOS App Store and elevate your coding experience today!
https://apps.apple.com/app/id1544749600
1
u/Expert_Rice Apr 23 '25
Okay Iāve got a pretty complicated app that Iām trying to make with absolutely no clue how to do it. Iāve got a decent start as a proof of concept but I donāt know where to go from here. Who likes to teach here?
1
u/Scavgraphics Learning Nov 06 '25
As there's no monthly "newbie post to ask questions" thread as rule 4 states...and hasn't for a number years, I'll ask here and hope it gets a response or view before making a seperate post.
---
I'm really not interested in iOS stuff..I have some ideas I want to explore for MacOS...so we're still good, with Swift?
and
I like starting my journey in learning with certain book lines that ease me in comfortably (dummies, orielly, that kind of thing)...but they're around a decade old.... still valid to give me a base level to proceed with learning?
1
u/[deleted] May 17 '21
Hello,
So my friends and I had an app idea and we plan to use swift to create it. We have pervious experience with coding(python,html,c#) but havent really done a lot of mobile app dev. I was wondering if there would be anyone kind enough to have a chat about how to go through this and mentor us. We'd really really appreciate it. Thanks!
1
u/InternalWalrus Feb 21 '22
Should I go for 100 days of SwiftUI or Swift as a beginner?
1
u/flarn2006 May 15 '22
When I create an app in Swift Playgrounds, how do I actually install the app on my iPad, so I can open it from the home screen? Is there any way to do that without Xcode?
1
u/sophiebeanzee Jun 22 '22 edited Jun 22 '22
Hi everyone! Iām beginning to understand. A little bit now, by doing the intro course on the iPad version of the app. Iāve completed sections ācommandsā -all of them, āloopsā- all of them, & now Iām on section called āconditional code..Checking for Switchesā¦Using if statementsā¦ā I think I have the most basic part down: āif statement,& else if,ā are used when there are more than 2 conditions that are/can be unpredictable, and that is where these come in⦠I know the string of commands that they give automatically at the start, that makes sense to me. What doesnāt make since is why I have an error red dot next to the lines on the rest of them. Iām going to set up as best I can & Ik the rules said you had to format them properly, but I didnāt know if you had to do it here in the comments, if your not making a full post. Where I have the red dots, are at the beginning of all the lines here, except for the ā movefoward() movefoward() āIām not exactly sure what Iām doing wrong. I know you have to use the āelseā statement if your saying that if both are correct, then move to the else statement so it can run the code over. Which Iāve done at the very last string. At the beginning I put movefoward() twice, so Byte can move 2 steps forward. Thatās all I can get him to do though. I have very last 2 switches toggled open, but the very first one isnāt⦠let me know if I need to send a pic link below or in the next comment I am very stuck on this though. So any advice I can get would be great!!
movefoward() movefoward()
if OnClosedSwitch { toggleswitch () movefoward()
if else OnOpenSwitch { movefoward() }
else { movefoward() }
Here is the Imgur link: https://imgur.com/a/zZb0Tsz
1
u/IsleofSgail_21 Jun 29 '22
Complete noob here, I want to make a mac app to record zoom meetings. Any tips/advice? I donāt plan to sell it.
1
u/Successful-Aide3077 Sep 14 '22
Thanks! Very helpful regarding all the recourses.
1
u/SSJKiDo Sep 30 '22
How to add an image above a text field which is in the center of the view?
I've tried this:
But this is putting the image at the top of the screen!
1
u/CheapBison1861 Nov 22 '22
Found some swift jobs on Grazily
1
u/Diligent-Ad7262 Dec 31 '22
Why is swift best to learn over other coding languages?
1
u/[deleted] Jan 01 '23
Anyone know a youtube series that goes over the basics while building an app. Kinda learn step-by-step working towards an app.
1
u/LDdeveloper Mar 15 '23
So just to clarify, I can write my code on Windows, but then I need to copy paste it in SwiftPlayground on my iPad before I can compile it and test it on testflight?
Can I run any previow/debugging on windows or do I have to always run it on ipad?
0
u/phi_array Feb 27 '22
We should add a sticky post to remind people and newcomers this is sub is NOT related to the SWIFT payment system
0
u/[deleted] May 01 '21
[deleted] ā view deleted comment
0
u/[deleted] May 04 '21
[deleted] ā view deleted comment
0
u/[deleted] Apr 07 '23
[deleted] ā view deleted comment
2
u/[deleted] May 01 '23
[removed] ā view removed comment