Good practices to become perfect iOS programmer

Tram Ho

What do you need to be a better iOS developer? That is what I will try to answer here in this article. Becoming great is an incredible level of knowledge and understanding someone never really reaches, but you can always be one step closer to it. Here in this article, I work very hard to improve myself everyday because that goal is my goal, to be great at what I do. In this post, I have collected some good practices and tips that I have learned in this ongoing improvement process.

In case you’re new to iOS, this post is the perfect complement to one of the tons of tutorials and tutorials out there. If you’re still looking for a good tutorial for beginners, check out Stanford University’s courses for iOS on iTunes U.

1. You should not use a single Storyboard file for your entire application.

Look at this storyboad. Seriously, this doesn’t make any sense. Here are a few reasons why you shouldn’t do this. A crowded storyboard is not maintainable. It is slow, you need a lot of time and effort to download and edit it. Also, if you work in a team and furthermore a developer has to make changes in the same storyboard, merging the code will be painful.

The best thing to do is to create a storyboard for each thread in your application. This is really useful because it keeps the storyboard small and clean. In addition, splitting the screen into an application flow will avoid merging code problems and reusing them more easily. This is easy to do, especially since Apple introduced Storyboard Reference in iOS 8, allowing it to make a difference for different storyboards.

2. Use Auto Layout

Auto Layout has been around for a while, it was introduced in iOS 7, so I think you’re used to it! The layout automatically calculates the size and position of all views in your view hierarchy, based on constraints placed on those views. Back in the days when we only had a 3.5-inch iPhone, we had no problem arranging the elements in the right position and size, but since the 4-inch, 4.7-inch screens and the newly released 5.5 inch, Auto Layout is a very useful tool that can save us a lot of time and make your application look better. Here is Apple’s official document about it.

3. Be careful when adding new views with coding

When you create a view using code and use the addSubview (_ 😃 To add it to the view hierarchy, you may be missing something. Auto Layout is based on the constraints and rules we set for each view, if you don’t add them programmatically, you’ll probably see everything is fine in your iPhone 5, but I tested it in 6, 6. Plus you will have problems.

4. Swift

The first time Swift appeared was in June 2014. It was 5 years old and growing fast! Each new version brings a lot of new features and improvements, and Swift 5 is no exception. But I personally think that the language is becoming more mature with every iteration, and eventually, the big changes that could disrupt your entire project will be less and less. Also Objective-C is dead, so go ahead and write code in Swift.

5. CocoaPods

CocoaPods is a dependency manager for iOS projects. Here you’ll find lots of third-party libraries that you can easily export to your projects, customize them and make your app great, while saving you time! If you don’t know where to start, please see this quick guide on how to add Cocoapods to your project. Always set the dependent version you want to install in your Podfile:

pod 'Alamofire', '~> 3.4'

This is important because if you leave it blank and install other dependencies later, this will update your old dependencies to the latest version available and you may have to fix your project to keep it. Everything works as expected.

Should you commit your Pods folder to your repository or should your Podfile force every developer to run the pod installation before starting to work? Everyone has an opinion on this, but we think running the Pod installation is the easiest and most practical thing to do.

6. Use vectors

Xcode 6 allows you to include vector images in PDF format in your .xcasset catalog. When you build your project, Xcode will create PNG @ 1x, @ 2x and @ 3x files, and iOS will use only the necessary images.

7. Use IBInspectable and IBDesignable

Tell a designer that asks you for a button with a border and a rounded edge. You can do this as follows:

Or install User Defined Runtime Attributes:

If I told you then you might have something like this:

Do you realize what just happened? You have configurable properties right in your Interface Builder and what’s more, you can see your changes directly in the storyboard without running your application. How does it work? Just create a subclass from UIButton with the following code (You can also create a UIButton class extension to provide this functionality in every node of your project).

If you want to learn more about this, we recommend that you read this article .

Share the news now

Source : Viblo