A Chemist Coding iOs

Husband, Parent, iOs Developer, Chemist, PEN, used to exercise.

Page 4


View Hierarchy Recursion

Just a couple notes here, nothing earth shattering.

If you have a custom UITableViewCell with controls of some sort and you want to know in which cell a the value of a control changed, there are a few ways, one of which is bad, one of which is good.

bad:

UITableViewCell *cell = controlItem.superview;

This is dependent on the framework implementation at the time and in fact does not work for iOs 7 & 8. In those versions you would use:

controlItem.superview.superview

The fragility of this is obvious, especially if you’re not thinking and implement it on a custom UITableViewCell that has a different hierarchy.

A typically better way to approach the problem is some form of this:

- (UITableViewCell *)cellForControl:(UIControl *)control {  
    while (view != nil) {  
        if ([view isKindOfClass:[UITableViewCell class]]) {  
            return view;  
        }  
        view =
...

Continue reading →


A Possible NSUserDefaults Alternative

It is often the case that we need to persist a few bits of info or at least a single object, like a “user”. Core data is too big for this, NSUserDefaults is sometimes not the best practice use case, and does not provide compiler auto-completion. The correct way is to create a (singleton) object for the data, and use NSKeyedArchiver for persistence, which is not super fast, but is straightforward and speed does not matter for small classes like this. It is not hard to use, but there are a few things that you have to do correctly. For a quick refresher, there are lots of examples, but this one is fine

  1. provide a method to encode each property of the object by encodeForKey by giving it an NSString key that is the same name as the property.
  2. Provide a method to decode each property the same way.

This leads to two problems:

  1. Must manually match the @“keyName” to the @property name. The...

Continue reading →


This is Why Politicians and Journalists Never Demonstrated Much Urgency About the 2008 Recession

If you rephrase the title…

This is Why People with College Degrees Never Demonstrated Much Urgency About the 2008 Recession

… then you only need about “a thousand words” to understand.

income chart

View →


Do Less

This is not bad.

I loved the busyness. I was firing on all cylinders. Spinning all these plates in the air. The world was my oyster!

And it all worked fine until…

…I cracked.

View →