Beware Xcode features that confuses an Android Developer

Image for post
Image for post

first attempt of using Xcode is at the beginning of 2018. As an Android Developer, I thought I should have a good grip on it as it’s just another mobile development platform.

However after trying it out, and my first experience on it, it confuses me so much, and that stops me from trying it again for almost a year. Until recently, get back into it, and have better grasp on it. From there I think could sum up this two confusing features that deter me from trying on the last time.

Share with you here so you could avoid the pitfall, and know how to handle it.

Constraint Setting

In Android, we mostly use Padding or Margin to distance a view from its neighboring view. In ConstraintLayout, we do add constraint between two views in the layout XML. Most changes are done in XML (programmatically)..

Sorry, I am not acquainted with the UI Design Interface in Android Studio yet

In iOS, setting Constraint is everyday life as AutoLayout is be backbone to the building the fundamental user interface.

Image for post
Image for post

The common way to set constraint is to use the below tool.

Image for post
Image for post

This is a relatively smart way of constraint a view to its adjacent items.

The Pitfall …

If you accidentally set it to a wrong value, what would you do?

Common sense would tell you just open up the same dialog tool as above and set it. When one click on it, it would show the exact value you previously set.

Image for post
Image for post

Your intuition would think that we could set it again, and it will reset the previous set constraint and replace with the new one. Right?

Image for post
Image for post

If you do that, it will set another constraint, and that will result in double constraint that could potentially conflicting with each other!!

The right way…

Before you set your constraint again, you could go to Size Inspector and you’ll see the constraints of your selected view there, as shown below.

Image for post
Image for post

Delete those no longer valid, then you’re all set to go add new constraint again.

Outlet Connecting

In Android, connecting a view in a layout to the code is usually done by referring to the ID defined in the XML file for the particular view. All are done programmatically.

However in iOS, the relationship between the User Interface and Code need a little magic behind to connect them. The user has to drag from the particular view and drop into the code to create the connection. Such connection is named Outlet.

Image for post
Image for post

This seems pretty cool as the code seems auto inserted with the type defined as well.

The Pitfall …

What if you you decided to change the name of the outlet. Just rename in the code will do, right?

Image for post
Image for post

You’ll get into some weird compilation error

Image for post
Image for post

The right way…

You could still rename it if you want, but you have to disconnect the previous connected Outlet. This is done through Connection Inspector

Image for post
Image for post

You could recreate the Outlet again, or just drag and drop from the Connection View to the Design Navigation view as show below.

Image for post
Image for post

I hope this post is helpful to you. You could check out my other interesting topics here.

Follow me on medium, Twitter, Facebook or Reddit for little tips and learning on Android, Kotlin etc related topics. ~Elye~

Written by

Passionate about learning, and sharing mobile development and others https://twitter.com/elye_project https://www.facebook.com/elye.proj

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store