Simple iOS App
I recently decided to start learning how to write mobile applications for iOS. I started learning Objective-C a while back but never really made it past the beginner stages. I figured since I had heard such great things about the new Swift language and how Apple had made considerable improvements to Xcode since I’d last used it, that I would give the whole mobile development thing another chance. I have quickly realized, even with all the aids and advances, I still need to learn a ton if I want to get anything worth while into the app store.
So to start out I figured I would create a few example apps for myself and who ever else might interested. For me, it has been difficult finding beginner examples so I am hoping to create a few myself. This post will cover the first of those applications. I have done many tutorials and read a lot about developing apps since I started but I think the best way to learn is to just jump in and start creating things.
I created the SimpleObjectExample app out of the desire to just make something that uses the basic apple objects to manipulate other objects (labels) within an app. I did this by simply scrolling through the Xcode object library and picking a few that seemed interesting and fit what I had in mind. In this app I use button, slider, switch, segmented control, and stepper objects to manipulate labels associated with each object.
I have had some difficulties getting used to iOS and Xcode in general, especially linking typed code via a UI. A lot of that just doesn’t feel natural at first. I figured creating this would give me some extra practice linking objects up to the code and making programatic manipulations. I have kept everything very basic so it can be used as examples on my future projects.
Another goal for this app was to make use of auto layout and create something that should be able to run on any screen size. This proved to be more difficult than I had anticipated. I wasn’t sure how to uniformly distribute my objects and dynamically move them around as the screen size changed.
Lucky Apple provides some amazing documentation and had an example I was able to use which can be found here. It is a little confusing to get the hang of, but after carefully going through the example I was able it link up my constraints to spacer views that move my objects when rotating the app or running it on different screen sizes. Here is a picture of the app with the spacer views visible:
After creating all the necessary constraints I then hid the spacer views so the objects seem to magically float from one position to another depending on the device or rotation. The blank spacer views are used to structure the application and the constraints around them are what causes the movement to happen. It is a little strange to get used to at first and it can be a real pain to tack down constraints that are causing issues. Luckily Xcode does a good job helping identify missing/ambiguous or conflicting constraints by providing helpful warnings and error messages.
You can access the source code for the app here. The main purpose of the app is to illustrate basic object manipulation and Apple’s auto layout features. Let me know what you think in the comments below. I am still very new to this stuff so any tips, tricks or links to example apps of your own would be appreciated.
6/19/2015