Skip to content
Go back

iOS tips

Easy to apply tips that can improve your development workflow.

Know available tools and how to use them.

I believe you should use best tool for the job, and there are lots of tools that are perfect for specific tasks. I wrote about tools I’m using

Write and use code snippets.

We often write similar code, stuff like dispatch to main thread, dispatch after, KVO etc. Use code snippets for that, this can save you lots of keystrokes and time.

Some of my most used ones would be:

I’ve asked others on twitter:

iOS devs: What are your most used code snippets? — Krzysztof Zabłocki (@merowing_) February 18, 2014

Some of the coolest ones I’ve seen are created by Kyle Fuller and Mattt

Just be careful not to break DRY principle.

Read clang/gcc documentation to explore some interesting possibilities

Examples:

 float4 test = {11, 22, 33, 44};
 test.xz = 2;
 NSLog(@"test %f %f %f %f", test.x, test.y, test.z, test.w);
  NSLog(@"floats");
  return fabsf(x);
}

__attribute__((overloadable)) double smart_abs(double x) {
  NSLog(@"doubles");
  return fabs(x);
}
static void someFunction() {
@autoreleasepool {
  	//! some code
  }
}

Use build phases, scripting and automation for your projects

Warnings

Add this build-phase script AFTER compilation and you will turn all TODO/HACKS etc into warnings (but still be able to use treat warnings as errors)

KEYWORDS="TODO:|VERIFY:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" -name "*.h" -or -name "*.m" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"

Icon versioning

Never again have someone test wrong version of your application.

Build number

You can use either very simple script like this one:

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${INFOPLIST_FILE})
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" ${INFOPLIST_FILE}

or do it properly by using agvtool

Script for graphing dependencies in Cocoa project

Great tool for seeing how tangled is your (or vendor’s) code, useful for refactoring or checking if agency that just send you some code knows anything about quality coding.

Use smarter breakpoints

Log all methods that are executed in your app

Avoid temporarly modifying code

Instead you can call NSLog from breakpoints and continue execution.

User space breakpoints

By promoting breakpoints to user space you can have breakpoints that exist only on your machine.

Fast jump to feature you are working on

By combining above 2 ideas you can execute arbitrary code eg. to enable some feature without modifying code, and you can promote it to user space so only you get that behaviour.

Conclusion

There is way more tips we could mention, but let’s leave something for future blog posts.


Share this post on:

Previous Post
iOS App Architecture, Part 1: Setting up
Next Post
Fit geek