3 Ways To Solve Your iOS Programming ProblemsMon 13 October 2014 by Jeroen Vloothuis
There are times when programming can be fun. And there are also times that make you want to pull your hair out and smash your head against the keyboard. Times when you are sure your code should be working but it isn't.
Here are 3 ways to help you get unstuck and help you keep your sanity.
1. NSLog or println
An easy way to get started is by using NSLog (for Objective-C) or println (for Swift) to look at your variables. Try to think beforehand about what the expected values should be. By placing println or NSLog calls at the right places you verify if they match your expected results.
// Given a variable like: var myStringVariable = myFancyFunction() println("Value: \(myStringVariable)")
// Given a variable like: NSString *myStringVariable = [self myFancyMethod]; NSLog(@"Value: %@", myStringVariable)
2. XCode Debugger
The debugger is a more powerfull, and often faster, way to look at variable values. You can use it by clicking / tapping on the gutter area next to your source code. A blue sign / arrow will appear.
When you run your program XCode will break on this arrow. Then you can use the bottom area of XCode to inspect values using.
For more info watch the WWWDC video about LLDB (the debugger).
3. Isolated Project
Sometimes the problem can be hard to isolate. In that case it's often a good idea to setup a new project. Then add just the code you absolutely need to give an example of the thing you are trying to accomplish. Try to substitute any other thing for hard coded test data or dummy views.
Often times just the act of setting up the system again in it's minimal form helps you see the problem. And if the problem still occurs you have a lot simpler environment to inspect and test with. You can even use this simpler setting when asking for help online.