Xcode 9 – Little Bits of Magic

Being a Swift fanboy, I have already downloaded Xcode 9 Beta and started delving into some of the cool features, CoreML and ARKit. However I find myself amazed at the little things, and I thought I would share one with you.

I like building views programmatically, and I won’t get into why or which is better storyboards vs. programmatic layouts, they both have their place. Normaly I create RGB values and store them in a struct to use all over my project, this way I can update them once and my whole project will update.

Screen Shot 2017-06-21 at 9.57.39 am.png

The only problem with this was when I needed to use storyboards I had to repeat my value again in the Attributes Inspector and being a programmer I hate repeating myself, but with Xcode 9 this is now a thing of the past. You can now create a colour set in the assets folder, and it can then be used in storyboards and code, see below for examples. So now my designer or I can update colours in one place, and it updates the entire app. Now, this feature is slightly buggy in the Xcode 9 Beta sometimes when selecting the colour in Storyboards you just get black, but Apple will have this fixed for the official release.

First, we create the colour set.

Xcode

Then we can use it in code.

Xcode View Controller

And in storyboards.

Xcode Storyboard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s