Hi All, I thought it'd make an interesting post (hopefully?!) to talk about the stuff that still, after about seven years of tinkering with iOS to talk about the stuff that still confuses me sometimes, or things I always have to look up.
Bounds vs Frame
Like, wow... this always gets me. I generally work at a higher level of abstraction, but usually when I come to this I have to google it again and again. Frame is relative to superview, bounds to itself. Use frame or center for positioning and bounds for doing stuff inside the view, such as cropping.
Objective-C Block Syntax
Compression Resistance vs Content Hugging
Let's be honest, AutoLayout has a hell of a learning curve, and by not touching UI much, I sometimes miss things with my spare time tinkering. I usually look up the below photo from @mokagio to remember. Also here's a good post on that.
Setting Text on a UILabel
Lol, like almost every time I do
myLabel = @"foo"; rather than
myLabel.text = @"foo"; Just one of those dumb things I can't seem to shake!
Logging a String
My brain is weird sometimes. I feel like my brain thinks "one day I'll be able to log an instance of NSString directly" so now and again I check. Nope.
NSLog(@"%@", myString); not
Of course, I know why it takes a string formatter argument rather than a string directly, but it still seems annoying to me. As I type this, I realise this could be "fixed" with a Macro?
There are a few things I used to get confused about but then suddenly don't.
When I first started learning AutoLayout, I was probably overthinking it or had the wrong mental model of how it worked.
The trick for me: Remember - two constraints, x pos and width, and y-pos and height. Satisfy those and you should be good to start with!
Dates and Times
Date and Time manipulation, formatting and timezones were always super confusing. My previous experience with these was with the C# DateTime library which worked a whole lot differently so it took me a while to get in the spirit of the Apple NSDate thinking.
The trick for me: Remember an NSDate is just an integer of seconds from 1970. The rest (timezone, format, components) is display.
I feel you were waiting for me to write this. People love to hate on provisioning but it's really not that hard? However, It can just break in so many ways and get frustrating. Just don't use the Fix Issues button (for now).
The trick for me: Taking the time to learn the parts. Signing Keys, Certificate, Provisioning Profile, WDC Certificate, App ID etc, Entitlements.
So that's my short list ranging from serious to less serious. I hope you feel less bad about being stuck on some things now. Remember: Chin up, you're probably not the only one feeling dumb about this stuff. Just ask!
How about you? What do you find confusing about iOS or development? Tweet me!
Thanks for reading!