Learning Swift, iOS, and Vapor in one week
Tags: ios, swift, beginners, webdev
Published: 2020-07-11 04:27:37

I always think of a line from *Silicon Valley* where the main character says, to prove how smart/good at coding he is, "I learned Ruby on Rails in a weekend" 

[![gif](https://y.yarn.co/de246995-2c76-455a-8a55-873478146830_text_hi.gif)](https://getyarn.io/yarn-clip/de246995-2c76-455a-8a55-873478146830) 

My bootcamp taught RoR in 6 weeks so maybe I can't say this, but I think if you had a solid coding background in other frameworks, learning RoR in a weekend wouldn't be hard, so that's just a funny TV vs. reality tangent. The wonderful world of internet commenters have also pointed out that the episode's timeline/character's age imply RoR wasn't around when he would have been 17 so... it might not be the show's most technologically accurate line!

But it's relevant to me because now I'm like, is it impressive to say I learned Swift, iOS, and Vapor in one week? Can I even really say I *did* learn it? It's kind of like saying I 'learned' a language by coding a `hello world` - not wrong per se, but it would obviously be a lot more impressive to say I built a full stack application with mobile/iOS frontend and backend REST API using Swift - and I didn't do that lol! I just did (parts of) a ton of tutorials and videos, used XCode for the first time, and used Vapor - a framework I had never even heard of before - all in about a week, so I'm feeling accomplished. 

I had also been feeling pretty down/discouraged about the whole job search process, and this kind of revived me. I mean there were also times where I was literally pulling my hair out at 2am wondering why I'm the dumbest person on earth. But equal amounts of feeling like a genius. Classic coding ups and downs.

I might never be able to brag about learning iOS in a week to sound smart, but I definitely dove into a whole new world of programming in a relatively short amount of time, and I learned some interesting things.

###Background

I find it hard to say exactly when I `started coding` or first learned `to code`. But I'd say I really started down the path to becoming a true and obsessive coder in October 2019. I read a book on Python, took an online course in web dev using Python/Flask, and in January 2020, I did the whole in person web dev bootcamp thing for Ruby, Rails, and React. 

A very common question for beginners is `Where to start? What language to learn first?` and a probably even more common response is, `It doesn't matter`. Just start somewhere, and then it's relatively easy to learn new languages, etc. from there. And it still amazes me how true that is!

{% instagram B8ge5TEAMcf %}

For me, looking back, starting with Python was great. But `Python/Flask` was hard. Very new and confusing, almost entirely self-taught. Then `Ruby/Rails` at bootcamp - still hard, but a lot better. I noticed small connections to what I already knew *and* had instructors to help me in person. Now `Swift/Vapor` - super hard, all on my own, very rushed, but also really cool, and I think kind of tied together for me how similar these 3 major backend frameworks can be. And also different! Same same but different. 

###Comparing backend/server-side frameworks

I'm not entirely sure what the best way is to compare backend frameworks. But I did recently see this video, and thought it was just a generally super cool visualization, comparing "popularity" based on GitHub stars:

{% youtube 8FQ4zW_F_Iw %}

The real difficulty over the last week was learning Vapor - a backend framework for Swift. At the time of writing this, `vapor` has about 19k stars. And Rails (the main backend framework I knew before this/compared almost everything to) has about 46k.

###So why did I choose to learn these things?

Well I'm probably too much in a `quantity over quality` stage in my programming life. I know the very standard advice about jack of all trades, master of none, don't just list as many tech terms as possible on a resume to look good. But these are desperate times. I'm looking for anything to distinguish myself from all the bootcamp grads who know React.

So when my bootcamp put up a free Swift course for us after graduation, I thought I'd check it out. XCode was a little scary - I still need to figure out all the shortcuts, and I still prefer my VSCode - but I liked it, so I put Swift/iOS on my resume (I'll admit this sounds sleazy, but I promise I didn't lie, and I said 'beginner in Swift/iOS'). 

And then I got an interview for a Swift backend position. I almost didn't even apply because it seemed so specific and out of reach. I'm not complaining or questioning it, but it is crazy to me how the world works out. I'm still in the interview process though, so I hope writing this doesn't jinx anything. 

But I didn't learn Swift *just* for this interview. I had only just started learning it, so when I got the interview, I spent the entire week leading up to it trying to become an expert in Swift and iOS. iOS wasn't as important for this specific interview - the position is backend, but for a mobile app company. But I wanted to be familiar with the basics of iOS development just in case.

##Swift and iOS

At first, I grouped these together. Of course, later, I get to the web/backend API side of Swift. But I started off just thinking ok, I need the basics of Swift and mobile. I still don't know the fundamentals of Swift that well. If you asked me to whiteboard a simple function, I probably could not do it. But I started off kind of skimming the resources from my bootcamp on Swift fundamentals, which helped to get a general vibe and at least be aware of the major differences from the languages I knew before. I checked out the Apple developer [docs](https://developer.apple.com/documentation/swift) and [Swift.org](https://swift.org).

If you really want to learn iOS, I think this video was the best resource I found:

{% youtube 09TeUXjzpKs %}

I skimmed/watched the first few minutes of many videos like this, and I thought this one was the best, especially if you're a total beginner. If for nothing else, it was really cool to see a `Hello world` app on my iPhone. It was like falling in love all over again 🥺

##Vapor

{% github vapor/vapor %}

I started off doing the tutorial with the most recent version of Vapor (4) but then my code challenge was in Vapor 3. It wasn't that difficult to go back to Vapor 3 but I did encounter some unrelated `brew cleanup` issues. Either way - check out the Vapor [docs](https://docs.vapor.codes/) if you want to try out the basic setup. 

There aren't a lot of blog posts on Vapor, as you might expect! React and JS are the top tags on here for a reason. But this was a very good, comprehensive blog post on Vapor that I found:

{% link https://dev.to/leogdion/a-vapor-guide-setup-and-deployment-with-heroku-and-ubuntu-49jn %}

###PostgreSQL and Fluent

This code challenge required PostgreSQL for the database, and Vapor uses Fluent as its ORM. This reminded me of my Flask experience back in the day, and Fluent reminded me of SQLAlchemy. I thought Postgres was just really hard to learn as a total beginner - but honestly I still struggle with it, even now, as a medium-beginner! And there aren't a lot of posts/explicit tutorials on how to use it. I always end up finding a mess of various docs/examples and typing so many wrong things into the command line before I finally come back to the same obvious, correct one. 

This is just to say - if you're a beginner using Postgres, don't be discouraged. There must be a reason why my bootcamp, and so many others I assume, start us off with SQLite and ActiveRecord in Rails. Again, totally might just be because anything feels easier in a structured, in-person context. But this bit from the Rails/Active Record docs makes me think I'm not wrong in thinking it's more beginner friendly:

>###Convention over Configuration in Active Record

>When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configuration code. This is particularly true for ORM frameworks in general. However, if you follow the conventions adopted by Rails, you'll need to write very little configuration (in some cases no configuration at all) when creating Active Record models.

This 'convention v. configuration' thing was a very interesting concept I remember loving at bootcamp. Like, it's so simple and obvious when you hear it, but I hadn't had the words for it before. This might be an oversimplification, but to me, convention over configuration means less writing actual code. Someone far more experienced than you has written the standard stuff. Almost like using a website creator template. You sacrifice flexibility (configuration), but you get more ease, speed, and reliability for basic use. When you're a beginner - you want convention.

So in my limited experiences with postgres and its relevant ORMs, I struggled with the heavier configuration aspect. Small side note for beginners - postgres/SQLite are examples of a `database management system` (DBMS) and ActiveRecord/Fluent are the Object-relational mapping framework (ORM). Overall, if you're reading this and you want yet another person's specific advice, start with something like `ActiveRecord/Rails` before something like `PostgreSQL/SQLAlchemy`.

###SwiftNIO

I noticed NIO a lot while debugging/seeing errors building my HTTP REST API with Vapor, so I thought it was worth mentioning. As far as I can tell, in simplest terms, it is a building block within Vapor for routing/creating API endpoints.

{% github apple/swift-nio %}

>SwiftNIO is focused on providing the low-level building blocks for these higher-level applications. When it comes to building a web application, most users will not want to use SwiftNIO directly: instead, they'll want to use one of the many great web frameworks available in the Swift ecosystem. Those web frameworks, however, may choose to use SwiftNIO under the covers to provide their networking support.

###Debugging in Vapor

This was, again, harder than debugging I've done in other programs. This could definitely be a lack of research issue, but from the brief googling I did do, it doesn't seem like an [uncommon](https://forums.swift.org/t/debugging-vapor-apps-is-harder-than-it-should-be/28640) feeling. 

I relied on writing my own tests, and adding basic breakpoints manually in XCode. In Rails, I used `byebug` and `rails console` a lot, and I didn't find anything analogous in vapor. All just things to get used to and keep researching.

###Conclusion

I actually loved trying to learn vapor, Swift, and iOS. I would highly recommend for anyone in a similar medium-level of experience range. I'd probably also recommend Swift and basic, frontend iOS dev for someone with no coding experience at all, because I found XCode to be generally more of a familiar user experience. It's a lot more visual, like you can manually drag and size a button to your iPhone simulator screen without even having to write code. 

This ended up being more of a reflection on my experience with this pretty wide range of technologies. I hope it was helpful. Maybe I'll do some more focused tutorials on specific Vapor examples next! Either way, if you made it this far, thanks for reading. 

###Resources

- [Swift docs](https://swift.org/documentation)
- [Apple docs](https://developer.apple.com/documentation/swift)
- [how-to-make-your-first-api-call-in-swift](https://www.freecodecamp.org/news/how-to-make-your-first-api-call-in-swift/)
- [designing-swift-apis](https://www.swiftbysundell.com/articles/designing-swift-apis/)
- [Swift wikipedia](https://en.wikipedia.org/wiki/Swift_(programming_language))
- [Vapor docs](https://docs.vapor.codes/4.0/)
- [Allow XCode access to your iPhone](https://support.apple.com/en-us/HT204460#:~:text=Tap%20Settings%20%3E%20General%20%3E%20Profiles%20or,prompt%20to%20confirm%20your%20choice.)