Quick Tip: Don’t Do This
I could not find out where a bug was coming from for the life of me today. Naturally it one of those “assignment instead of equality” bugs that seem to crop up when trying to code too quickly. The difference here was that I had implemented a subclass of NSObject that reimplemented the method +resolveInstanceMethod:. So, the code went like this:
+ ( BOOL )resolveInstanceMethod:( SEL )sel
{
if ( sel = @selector( setFoobar: )) {
return class_addMethod([ self class ], sel, ( IMP )setFB, "v@:@" );
} else if ( sel = @selector( foobar )) {
return class_addMethod([ self class ], sel, ( IMP )getFB, "@@:" );
} else {
return [ super resolveInstanceMethod:sel ];
}
}
For those of you keeping score at home, when the Objective-C runtime tried to resolve any selector, this method happily added a selector for -setFoobar: to self’s class and returned YES.
Don’t do this.
Using Apple’s SimplePing on iPhone OS
If you try out of the box to compile Apple’s “SimplePing” code sample on the iPhone OS, you’ll wind up with a lot of errors as some files don’t exist in those SDKs. Specifically, you need these files (you need more than just these files to compile, obviously, but these are the ones that aren’t included):
/usr/include/netinet/ip.h/usr/include/netinet/in_systm.h/usr/include/netinet/ip_icmp.h/usr/include/netinet/ip_var.h
So here’s a quick Bash script that links the relevant files to your iPhone OS and iPhone Simulator SDKs:
for path in /Developer/Platforms/iPhone*/Developer/SDKs/*; do
for file in /usr/include/netinet/ip.h \
/usr/include/netinet/in_systm.h \
/usr/include/netinet/ip_icmp.h \
/usr/include/netinet/ip_var.h; do
if [ ! -f "${path}${file}" ]; then
sudo ln "${file}" "${path}${file}"
fi;
done;
done
I’ve spoken to an Apple engineer and confirmed that this is the best way to do it, as well as filed a bug, which I encourage you to do as well if this annoys you.
