MobileCraft

May 17 2013

Using the XCode debugger

Using an debugger is an critical skill for any developer and can really improve your development.

Here’s why you should use the debugger:

  • It’s faster: You don’t need to restart/recompile. Just set a breakpoint and you can start inspecting your app right away.
  • It does not change your code: no need to add NSLog to your code and no risk of inadvertently commit those debugging lines.
  • More information: The debugger lets you inspect all variables in the breakpoint’s scope, but also the stack trace. This means you can trace the calling functions or methods (as well as their respective variables)

Fortunately, Xcode embeds an debugger (gdb). Xcode offers a super-easy interface for interact with the interface, showing the stack trace, variables, the console and controls.

Adding a breakpoint is easy as clicking on the left of your code. To move it, simply drag-and-drop it at its new place. To remove it, drag-and-drop it outside of the area.

image

You can also edit the breakpoint by right-clicking on it.

image

Edit lets you add actions (like print object) and specify not to stop on this breakpoint.

image

To run the app with the debugger, be sure to enable the breakpoints.

image

When it reaches a breakpoint (and given breakpoints is enabled and the breakpoint doesn’t have Automatically continue after evaluating option enabled), the debugger will suspend the execution. You can the inspect the stack trace.

image

And also variables in the current scope and well as a console to manually interact with the debugger.

image

The debugger controls let you resume the program, step over or into instructions.

image

In conclusion, the debugger is a super useful tool. If you are not already using it, I urge you to try it out. I’m sure you’ll get addicted and won’t be able to work without thereafter!

May 14 2013
May 11 2013
simulator notifications library
May 01 2013
prototype xcode
Apr 04 2013

Parse doc set

To add Parse.com documentation to Xcode, add http://parse.com/docs/ios/com.parse.Parse-iOS-SDK.atom to the documentation sources.

parse documentation
Apr 03 2013

NSMeetup Hackathon

Last Saturday, NSMeetup organized a Hackaton.
Meeta and I decided to work together on an app to let people make a social bucket list. We called it plnr.

It was Meeta’s first app UI design:

image

I tried Parse for the first time. It is super easy to use and well documented. I really recommended it, especially if you don’t want / don’t have time to mess with servers/backend.

It was a really great experience. Thanks everyone at NSMeetup.
I’m looking forward the next meetup. And we hope to finish plnr and release it!

event hackathon meetup app design
Mar 28 2013

Loading an image in unit tests

You can’t use imageNamed in unit tests. Instead, do the following:

NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *imagePath = [bundle pathForResource:@"photo" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

unit test sentest image bundle
Mar 15 2013
class runtime storage
Mar 12 2013
documentation block
Mar 08 2013

(Ab)using Objective-C runtime messaging

A while ago, I added FilePicker to one of my apps, Tactilize. We wanted to change the design of FilePicker in our app. But this was rather tricky because the SDK comes as a closed-source static library. Following Alex’s article, I started playing with the runtime to change method implementations.

I messed a little bit more with the messaging feature of the runtime. If you are interested, have a look at my MessagingTests repo on github. In this repository, I’ll try a couple of things:

  • Replace a method implementation by another: the easiest thing to do, by using class_replaceMethod
  • Replace a method implementation by another, calling the original method: keep a reference to the old implementation, replace with the new implementation (class_replaceMethod), re-add the old implementation under a different selector (class_addMethod). The new implementation perform the selector to the old implementation.
  • Replace the superclass’s method implementation: we change the superclass’s implementation, which behavior depends on the class. If you’re messing up with NSObject, this is probably as dangerous and ethically questionable as human stem cell research (just joking, but still - I don’t recommend this in production!).
In the end, we didn’t implement this in our app. But it’s still fun playing around with the runtime.

1 note

runtime class
Mar 06 2013

Hourglass

Hourglass is a library to execute code depending on time. For instance, you would like to do a certain action if and only if you didn’t do that action recently.

Hourglass was first implemented as a class. Later, I re-implemented it in a simpler function form, inspired by the dispatch functions. Here is a description of it:

Execute a block if some 3 seconds elapsed since last time we run the hourglass (or called hourglass_set, see below)

NSString *key = @"my_action";
hourglass_run(key, 3, ^{
    // do something if more than 3 seconds since last time we did _my_action_
}, ^{
    // do something if less than 3 seconds since last time we did _my_action_
});

Reset the hourglass

hourglass_clear(key);

Set manually the hourglass

hourglass_set(key);

Check manually if 5 seconds are elapsed

BOOL isElapsed = hourglass_elapsed(key, 5);

1 note

library
Mar 05 2013

The “Merge VS Rebase” debate

Ok. I’ve had this blog post draft for months waiting to be published, then changed it, again and again.

There are pretty clever people out there having good reasons to use rebase instead of merge in git. See Merge vs. rebase – a deep dive into the mysteries of revision control, Rebase v Merge in Git and Git merge vs. rebase, Avoiding Merge Commits in Git (and lot more here).

Here are rules from what I understand:

  • Rebase to pass changes from the top of hierarchy downwards and merge to flow them back upwards.
  • Never rebase branches that you pulled. Only rebase local branches.

The rationale is: if you merge the master branch into your feature branch (to get it up-to-date), then merge your feature branch into master (to publish the changes), you’ll end up with two merge commits.

But there seems to be a lot of confusion on how exactly rebase works. And to be honest, I’m not really sure either.

Apparently, it is possible to lose commits (this means code) if rebase isn’t used correctly.

As an engineer, the only think I’m sure of is, besides features implementation, quality control, continuous integration, analytics, AB-testing, user experience, graphic design (and lot more stuff), code safety is top priority and I don’t want to lose any code, nor impact any of the aforementioned tasks or processes.

I don’t care if merge doesn’t give me nice-looking commits, as long as I am sure we don’t lose anything.

tool git
Mar 01 2013

Image Autocomplete for Xcode

KSImageNamed is a autocomple Xcode plugin for images.

image

xcode
Feb 28 2013
vagrant
+
debugging
Page 1 of 7