My 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.
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.
The common way to set constraint is to use the below tool.
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.
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?
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.
Delete those no longer valid, then you’re all set to go add new constraint again.
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.
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?
You’ll get into some weird compilation error
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
You could recreate the Outlet again, or just drag and drop from the Connection View to the Design Navigation view as show below.