UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Swift Knowledge Base

Free example code you can take and re-use in your own projects.

This is the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift 5.4. You can search all questions by typing below, or browse by category.

If you like this, you should check out my resources to help you learn Swift for free.

Browse by category…

Looking for SwiftUI?

SwiftUI is such a big topic that it has its own dedicated guidebook: SwiftUI by Example. This follows the same hands-on approach as the Swift Knowledge Base, but goes into much more depth to help you get started faster.

Frequently asked questions

Can I use this code in my project?

Yes! You can use this code however you want in your app projects, commercially or non-commercially, and with or without attribution to Hacking with Swift. You don't need to ask us; just use it.

Why is this better than just using Google?

Swift is a language that has changed a lot since its launch, and continues to change with every new Xcode release. This frequently makes it hard to find answers to common questions, because what worked a year ago is today probably incompatible! So, I made this as a one-stop-shop for 600 of the most common questions I get asked about Swift, and I made sure the answers were fully updated for Swift 5.4. You don't need trial and error: everything is written for Swift 5.4.

Why are some answers so brief?

I tried to make every answer brief, because when you're looking for answers you don't want to read waffle. If you're looking for answers and only answers, this is the right place. If you're looking for explanation and elaboration, you should read the main Hacking with Swift tutorial series.

Why are some answers so easy?

I get a lot of questions from readers every day, some on Disqus, some on Twitter, and some by email. I've tried to make the answers you see here representative of the questions I get, and it's true: there is a huge range of skills out there. So, some questions are easy, some are hard, and some are in between – and that's OK.

Why is there nothing about SomeAwesomeClass?

Like I said, these questions were put together by summarising nine months of messages from readers, so if I missed something off it's probably because I wasn't asked very often or at all. If it's something you feel very strongly about, send me a tweet @twostraws.

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.