Categories
Computing iphone Mac OS X

Private methods in Objective-C

Coming from the Java world, I love, care and embrace all things private, including private methods. Objective-C supports the feature but it appears to me (based on very shallow Googling) that there is not too much familiarity (or use) with it. I looked in a book I recently acquired, Learn Objective-C for Java Developers (Learn Series). While not a book a perfect book, it does cover the how-to of private methods in Objective-C.  

The key to the approach is to leverage Objective-C categories. Categories are a mind-blowingly nifty in the fact that they allow you, among other things, to augment objects you did not create with your own methods. While there are other ways of 'hiding' private methods, most of them result in warnings in Xcode. So here goes…

Say you have an object called CoolWidget. You create the header file (CoolWidget.h)for it as usual, i.e.:

@interface CoolWidget:NSObject
{
    int publicVar;

    @private
    int somePrivateVar;
}

// public methods
-(void) doSomething:(BOOL)cool;

@end

To add private methods to it, you would create a category for the object in a separate header file (CoolWidget+Private.h):

@interface CoolWidget (Private)

// private methods
-(void) doSomethingPrivate:(BOOL)cooler;

@end

All that's left for you to do is to include the additional header file, CoolWidget+Private.h in your implementation file, CoolWidget.m (though categories are often/normally implemented in their own .m file).

Update:

As my friend Glenn Barnett points out in his tweet, there is no such think as private methods in Objective-C. Unlike C++ or Java, there is no real 'enforcement' of access to the methods. Privacy, overall, is purely by convention. 

Share
Categories
Computing iphone

iPad: Did the laptop just die [A Facebook discussion]

I want to believe that I know (ok, encountered) a variety of smart and interesting individuals in my life. Apple, as an amazing brand, warrants a lot of emotion from its followers. The release of the Apple iPad caused so much excitement and discussion that it hobbled Facebook and Twitter. So when I set my Facebook status message to 'Did the laptop just die?' in reaction to the iPad's launch, a tsunami of insightful comments ensued. I want to share it with the world as a snapshot to be revisited after common mortals get their paws on the device and we can judge it ourselves. (Persons names shown in acronyms)

YZ(Me): Did the laptop just die?
    
BS:
Not unless you like a device that can only do one thing at a time, doesn't run desktop application, doesn't have a replaceable batter and can't run flash 😉
Yesterday at 2:32pm ·  
 
TR:
Maybe they should have come up with a name that doesn't evoke images of a feminine hygiene product.
Yesterday at 2:33pm ·  
 
YZ:
You want to tell me you do not use a sanitary slate?
Yesterday at 2:33pm ·  
 
RWK:
Not since I got an iUD! Badoomchoo
Yesterday at 2:42pm ·  
 
MB:
That was the sound of the now clearly overpriced Kindle dying.
Yesterday at 3:10pm ·  
 
CA:
Don't forget that it can only run approved applications, and view approved content. Who cares how "shiny" it is, or how it can (or can't) multitask, if you can't do what you want with it? I wouldn't pay $5 for it.
Yesterday at 3:25pm ·  
 
YZ:
I think Apple calculated the loss of the CA: population. They will go ahead and sell it anyway.
Yesterday at 3:26pm ·  
 
TR:
The Kindle is half the price of the iPad and maybe some of us just want to carry a thousand books around. Apples and oranges comparing the two, same form different function.
Yesterday at 3:29pm ·  
 
MB:
Half the price: single function, monochrome, passive display, no multi-touch. The market will determine whether the Kindle has a future at half the price, but to me it looks like a lot less than half the value.
Yesterday at 3:36pm ·  
 
YZ:
I am starting to like this new 'agreeing with MB:' thing.
Yesterday at 3:37pm ·  
 
TK:
iPad will sell like hot cakes, however I am really disappointed you cannot draw onto it with a stylus / pen. That would have made it extraordinary for me, and probably changed the way designers work. Also, no multitasking is crap. Someone will jailbreak it though, and make it a whole load better.
Yesterday at 3:41pm ·  
 
CA:
Why would that be revolutionary for designers? Wacom (and others) have made devices like that for almost 2 decades.
Yesterday at 3:44pm ·  
 
MB:
Two words, CA: direct manipulation. Wacom tablets are almost as disconnected as mice. The result of you intent does not show up under your stylus but on a separate screen. Had Apple allowed for use of a stylus, we would finally have a digital canvas.
Yesterday at 3:50pm ·  
 
CA:
I understand the difference between a tablet and a touch screen (and can see the advantages) – and Wacom (amongst others) makes both. For example, checkout the Wacom Cintiq series, HP's TouchSmart, 3M's single and multitouch displays, MagicTouch's product line, etc. Why would an Apple device be a "digital canvas" when other devices (even those that work with MacOS) would not be?
Yesterday at 3:58pm ·  
 
TR:
Maybe I don't want something that's multi-function, technicolor, and interactive, because I've already got a MacBook. I don't buy things because they're cool. I buy them because they work and do exactly what I want them to do – such as carry around a thousand books. If I'm carrying a MacBook, a Kindle and an iPhone, why would I add an iPad? "Mini" laptops have generally failed so far. Could the market already been too crowded?
Yesterday at 4:10pm ·  
 
TK:
Cintiqs have poor resolution, and are expensive. If iPad has same res as the iphone, it would be very sensitive and really nice to draw on.
Yesterday at 4:11pm ·  
 
MB:
Interesting, though design certainly matters, I don't think I factored "cool" into the price calculation. 😉

You wouldn't add an iPad to your trio: you'd replace your Kindle (period) and MacBook (when you are not at your desk).

Lastly, I think the value of large screen, affordable multitouch UI has yet to be explored. I tried the Kindle but … See Morecould not get past the controls. The iPad solves that issue. Not sure whether I'll be version 1 (because I also already have a MacBook and an iPhone), but I can see the attraction.
Yesterday at 4:54pm ·  
 
NC:
sorry MB, you'll be disappointed…. What everyone seems to forget is half of what makes the Kindle a solid product is the e-ink. Without it, iPad users are just BEGGING for migraines… You'll be reconsidering the Kindle (or Nook) in no time… iPad === Newton === FAIL (Though we all agree it will sell a ton; then again, didn't the Phantom Menace sell a ton of tickets too? )
Yesterday at 5:12pm ·  
 
MB:
Maybe, NC. I stare at my computer screen for hours every day with no migraine. How is this different?
Yesterday at 5:30pm ·  
 
MB:
Also, as someone pretty attuned to user experience, I really felt that the Kindle must be succeeding *despite* the ui. I used it for a month and returned it.
Yesterday at 5:34pm ·  
 
NC:
Come on MB, you've seen heatmaps, you know that reading eye movements differ from typical computer use… Eyestrain ensues.
Yesterday at 5:43pm ·  
 
NC:
btw, I will concede that the UI on the iPad will be better than a Kindle. I'm saying that the core reading will be far worse…
Yesterday at 5:44pm ·  
 
MB:
I'm sure individual mileage will vary, eye strain wise. Clearly, when reading is the primary purpose readability is paramount; I just found the UX (UI + controls) of the kindle to be a dealbreaker.
Yesterday at 5:50pm ·  
 
TK:
Apple is well on the way to dominating the mobile devices market, not only through the device itself but the UI. All these systems share similar interfaces- total compatibility. No need to learn anything new, it's second nature. This has been Apple's strength always.
Yesterday at 6:04pm ·  
 
TR:
I agree with everything NC says. Also, am I the only person to have owned three touch-screen devices and hated them all? I'd rate the Kindle the easiest device I've ever learned to use – tremendously easier than the iPhone. Maybe I'm just too old-school for the paradigm. Also when I'm on 10-14 hour flights – as I oftem am – I could never read books on a computer-style screen.
Yesterday at 6:14pm ·  
 
MB:
TR, I think the UI paradigm of the Kindle and the iPhone/iPod touch/iPad are pretty diametrically opposed.

Also, I think nailed the ultimate difference between the iPad and the Kindle: the Kindle is (overwhelmingly) a single purpose device: reading. iBook on the iPad is just one other application, not the primary purpose of the device.

However, I do think the iPad will dominate the "ereader" market in the education space in a way the Kindle and Kindle DX hasn't.
Yesterday at 6:21pm ·  
 
TR:
Apple isn't on the way to dominating the mobile device market until they make a phone that's accessible to the 95% of the world that can't afford to buy an iPhone. They're on their way to dominating the smartphone market, but Nokia is still making a million cheap phones *per day*. Do you really think Apple is going to start supplying cheap mobile phones to Africa and China? No moreso that you'll see Ferraris on the roads of the Sudan.
Yesterday at 8:28pm ·  
 
TR:
For anything to dominate the eReader market in the education space (which is a tiny, tiny market), textbooks would actually have to be available in eBook format. Very few are. It's not a device problem, it's (if I may be so bold to say so) a format and content management problem. The worst thing about owning an ereader is that so many books aren't available in the format.

The best UX rareley makes for the most successful product. There are so many other factors.
Yesterday at 11:02pm ·  
 
MB:
An excellent user experience ALONE rarely makes for the most successful products, but an awful user experience can ruin a product's chances all on its own.
Yesterday at 11:06pm ·  
 
TR:
Most successful products have mediocre/passable UX, and succeed based on other factors. Top example would be the Blackberry.

What do you think?

Share
Share