Sunday, September 23, 2012

The evolution of lazy initialization

Lazy initialization is tent pole of Objective C. Apple placed a lot of emphasis on using the pattern in the early iPhone days. That was justified especially considering that the original iPhone shipped with 128MB of RAM, compared to the latest iPhone 5 with 1024MB of RAM.

In the beginning


The ARC evolution


The ARC evolution was fairly tame, allowing us to move the ivar into the implementation files. While the original method was great, and served me well until ARC. With no need to dealloc, and the ability to have iVars that aren't declared in the public interfac.

Clang takes it up a notch


With the most recent versions of Clang you no longer have to use the @synthesize & @dynamic keywords when making @property declarations.
This is all well and good, but I don't want to write my own ivars if I don't have to. So I've set about exploring ways that I can do away with having to create my own ivars.

Option 1.

This approach is comprised of three steps
  1. Public readonly property declaration
  2. Private readwrite property (re)declaration in a class extension
  3. Assign our instance to the ivar

The problem with this is that there is still the ability to overwrite the ivar. Granted it's only from within the class, but still not ideal. This could be an advantage as if you decide to move away from the pattern all you need to do is set the ivar via the mutator.

Option 2.

Another alternative, is to take advantage of another clang feature, where we use the @synthesize directive, to generate a backing ivar on request, without having to explicitly declare the ivar, or at least declare it in a conventional way.
Along with being the smallest version, we can specify the format of our private ivars, so if you want to suffix your underscore rather than prefix it, you have that option.

Whats the solution?

Quite frankly, i don't know. I'm leaning towards Option 2 as it doesn't provide an mutator for the ivar, and so there is almost no suggestion that the ivar should be mutated by anything thing other than the lazy accessor. However I'm interested to hear the opinions of others.

Thursday, September 20, 2012

I Took a Picture [Cambodia Edition]

A sunset in Sihanoukville, Cambodia

Social.framework

It feels like an eternity since it was announced but iOS 6 is finally available to the masses, and we can now talk about the all the (few) new goodies that it contains.
Apple included the Social Framework in iOS 6 as an abstraction layer for accessing the various social services that are now included with iOS. The key feature here is that you never have to deal with the Facebook SDK again if you wish...
So let's explore how you can use the new Social framework classes to replace REST API access functionality that is provided via the Official Facebook SDK
TL;DR; Sample code

Create an ACAccountStore

According to Apple's developer documentation the ACAccountStore
[ACAccountStore] provides an interface for accessing, manipulating, and storing accounts. To create and retrieve accounts from the Accounts database, you must create an ACAccountStore object. Each ACAccount object belongs to a single ACAccountStore object.
A simple alloc && init sent to ACAccountStore will suffice. Perhaps the easiest thing you'll do this week.

Get the Facebook ACAccountType

The 2nd easiest thing you'll do this week

Request access to currently logged in Facebook User

Before the callback block is called the User will be presented with a UI to confirm that they want your app to have permission to access this API. In the event that initial permission has been revoked, or disabled you will be given a negative boolean value.

Select an authenticated ACAccount

Your block will need to reference your ACAccountStore instance in order to see which accounts you have access to. To actually access the accounts you need to call the accountsWithAccountType: method which returns a NSArray of ACAccount objects. Where the type argument is account type we got in the previous section.
Apple has designed the ACAccountStore class to support multiple authorised user accounts. While iOS 6 only supports a single Facebook account, it does support multiple Twitter accounts. So while it is safe to assume that first (and only entry) in this collection is the ACAccount you want to use, the same cannot be said when you are working with Twitter accounts. Ideally you would want to present a 'picker' UI to the end user.

Construct a SLRequest

SLRequest is the Social frameworks NSURL request abstraction to enable it to support request signing, and token passing, features used by Twitter and Facebook. The SLRequest class also has a convenience method for dispatching this request.
If you are a fan of request queuing, and application wide request management there is also the option to extract a prepared NSURLRequest object with you can then pass to something like an AFNetworking request operation (See below).


That's it! If you weren't able to string the process together in your head magically, you can view the entire gist. Thanks for reading!

Tuesday, June 19, 2012

Parse + CocoaLumberJack = Remote logging

I love logs, they're just so useful. Usually when i want to do some logging i save the data to a CSV file using my FRCSVFormatter. However, i've been wanting to try out Parse for quite some time, so it was mash up time.

CocoaLumberJack is probably my favourite logging framework. Thanks to it's modular nature you can easily create your own log formatters, or in this case create your own loggers. What i've done is implement a Parse "objects"inside of a DDAbstractLogger subclass  which enables this ...



I've added in the [[UIDevice currentDevice] name] so that you can differentiate between the devices. You could also sort my messages, method name, file name and line number.

Check it out on Github

Wednesday, May 16, 2012

Around the sun and back again

One year on the road, and through almost zero planning i've ended up in the place that i've started, retracing a route that i previously travelled.

I coined a new phrase today, "My impressions of so much, are coloured by my knowledge of so little". It would appear that i have more to learn.

Sunday, April 29, 2012

一月在香港 ... One month in Hong Kong

Wan Chai & Central
Hong Kong is without doubt my favourite city on the planet. One of the things that i love the most about the place is how the buildings seem to twinkle at night, almost as if they are suggesting that they know something that you don't.

Something i had overlooked in my reading about the city was the cities architectural past. The Skyscraper laden strip of land that makes up the northern shore of Hong Kong island, used to be full of old Victorian buildings at the turn of the century. If you have an interest in colonial architecture, i highly recommend checking it out.

Three of Hong Kong's prominent buildings, (from left to Right) Bank Of China Tower, IFC 2, and the center.
I've always said i would love to live here, how realistic a possibility that is, i have no clue. But i'll certainly try to make it happen.

Sunday, April 15, 2012

Tiger Leaping Gorge (虎跳峡)




One of the last big things i did before i left china was to visit Tiger Leaping Gorge (虎跳峡). This had slipped off my agenda when i heard about the fantastic trekking opportunities that were to be had around the town Deqin (德钦), however i cannot explain in words ho cold it is 3600m up near the Tibetan border. So needless to say my time in Deqin was extremely brief.

The lack of a proper excursion in the foothills of Tibet meant that Tiger Leaping Gorge was back on the agenda. One of the reasons that this wasn't especially high on my agenda, is having trekked around Hawaii, and Australia by myself, i've found it really is more fun with company. Especially when you get into that classic "Do i go this way, or that way" situations.

My company came in the form of Peruvian woman that i met in Shangri-la (香格里拉) called Alessandra.  Together we walked the 18km from the upper gorge to the middle gorge. The whole trip took about 7-8 hours including a stop at one of the guesthouses half way to eat and pick Snickers bars (巧克力) for the trip.

The trail's configuration is a mixture of public roads, dirt trails, and steps hewed out solid rock. One of my favourite bits, and one of the most interesting is this waterfall (Image left). The gorge sits between two Gigantic mountains, both reaching well over 5000m at there respective peaks. As result melting snow running down the mountain(s) provides these amazing features. There is essentially no path at the waterfall, the water from the waterfall runs over the "designated" path and off the edge of the cliff.

While the water isn't a deep, it's not particularly dangerous (well as long as you don't lose your balance while taking HDR photos), it is an awesome experience to be perched between this falling fresh water and a 1000m drop down into the gorge.

So i have a disease, i'm an addict, a Computer addict. As a result of my disease i see it necessary to carry my Macbook everywhere me. Well in this case, i didn't feel comfortable leaving it at the starting Guest house, so i thought i really ought to bring it with me. The fact that i had a new episode of Family Guy, and had been doing quite well in my FM12 game did not influence my decision in any way shape or form.

Needless to say after a few kilometers it began to dawn on that i really needed to somehow make the fact that i was carrying a 3kg laptop with me 18km, worthwhile, The below was the result.


In many ways it actually sums up my trip quite well, travelling the world, glued to my laptop. Sometimes a consumer, others a contributor, but most importantly a creator.

But i digress, after the trek i was well and truely shattered. My legs hurt and while the pain did subside over the next few days it was still fairly taxing. Nothing that would have me advise people not to do the trek, but make sure you don't plan on doing much afterwards.

Anyways if your interested in seeing my route in additional detail, i've used my billion dollar GPXShare app to upload my GPS trace, which you can enjoy here.


To close, Tiger Leaping Gorge was impressive, the views amazing, however from the short amount of time i spent in Tibetan hinterland that was Deqin, and the feilai temple (飞来) i'm confident that even better trekking is to be had there.

Thursday, April 12, 2012

Dinner Diary - 馅饼(xian bing)


Sadly my second trip to China hasn't been filled with anywhere near the same amount of street food as i had hoped. Maybe 云南人 just don't like eating on the street, who knows. Having said that i found 馅饼, without much searching. It's very similar to the Baba that is found in northern Yunnan, however this is filled with pork mince and cooked in large amount of oil, so much that it's almost dangerous for health and clothing to eat it with your hands.

一个馅饼是6元
One xianbing is 6 yuan (£0.60)

Thursday, April 05, 2012

Dinner Diary - Naxi Sandwich

This one isn't a traditional recipe as far as i know but instead a western take on a authentic Chinese food. "Baba" is a traditional flat bread from Naxi people in Yunnan province. This sandwich is essentially two pieces of Baba with a fried egg, tomato, red onion & cucumber. It's fairly awesome, and has a really fresh taste. Another "fusion" dish was "Chocolate Baba", sadly this was only chocolate sauce on a Baba, not chocolate inside a baba (huge difference).

Anyways this Naxi sandwich came in at 16 Yuan (£1.60)

Thursday, March 29, 2012

Dinner Diary - Hanoi Mystery sweet


Vietnam is a good place to be if you like sweet things. Kem Flan, Ca phe sua de, and the is mystery food. It was possibly the cheapest thing i got in Vietnam, costing around 5000 Dong in back alley of Hanoi.

It was essentially like cornmeal porridge on a rice cracker with sugar sprinkled on top. Sounds basic but it was awesome, and extremely sweet.

Dinner Diary - 粑粑 (Baba)

Yum, bread. It's like it's been the theme of my time in South East Asia. the place i had always sworn that you could not get decent bread.

Baba apparently comes comes from the Naxi minority people in Yunnan province, China. Sometimes it's filled, sometimes it's just plain. The joy is in the discovery. I've had at least 4 different types of Baba in the same town. One with Red bean filling, one with a sweet jam like filling, a plain one, and a baked (rather than fried) version.

Baba on the streets on 大理 ranges from 2 yuan all the way to a mind shattering 5 yuan (daylight robbery if you ask me).

Dinner Diary - Dali Noodle Surprise


It seems to be almost customary now that i try random things in random countries. The above dish is one such example. It consisted of Rice noodles (米线), strips of pork, and the shop had a series of veggies and spices that you could add to it. I just threw in handful  of spring onions.

This dishy dish came in at 6 yuan (£0.60p).

I Took a Picture [Tibetan Edition]

Meli Snow Mountain, Tibet. Taken From Feilai Temple, Deqin, Yunnan

Sunday, March 04, 2012

Dinner Dairy - Bo Bit Tet


Since i've been in Vietnam, i've eaten a lot of food. But i think with Bo Bit Tet, i've found one of my favourites. This is especially unusual as there is very little Vietnamese about it. The dish is made of a salad, chips/ french fries, a bread roll and "steak". Beef in South East Asia is a far cry from the meat in Europe & the americas.

What makes this dish so good is the gravy/ sauce. Oh the sauce! It was so good i had to purchase another Banh mi (bread roll) to sop up all the sauce.

The Bo Bit Tet cost 60 000 Dong (US$3/£2) on the rainy, cold streets of Hanoi. Incase your interested the additional bread roll cost 3000 Dong (£0.10p).

Thursday, March 01, 2012

Dinner Diary - Bun Cha


Today's dish was Bun Cha. Unlike a couple of the recent postings i actually knew what i was getting into with this one. Having seen the signs up on the streets of Hanoi, i had done a small amount of research and knew what to expect. The soup is slightly sweet, and together with the noodles and veggies makes a great combination. Floating around in the soup are bits of BBQ pork wrapped in various leafs of one form or another. It's usually eaten by popping some noodles and veggies into your soup, and letting them soak up a little of the flavour, before popping the whole deal in your "pie hole". On the streets of Hanoi's Old Quarter, it cost 30000 Dong (US$1.50/£1)

Sunday, February 26, 2012

Dinner Diary - Vietnamese Train Surprise


So i'm sitting on a train somewhere between Hanoi and Da Nang when a train company employee passes by my hard sleeper hawking some stuff. Having seen a couple of other vietnamese people go for it, i thought why not. Inside the white casing which was nicely wrapped in a leaf, was a mince pork filling with a quails egg, Quite tasty. The unfortunate thing, is i have no clue what it is, but it was "cheap-ish" for train food coming in at 30000 Dong.

Friday, February 24, 2012

I Took a Picture [Central Vietnam Edition]

Hoi An, Vietnam, 3 Exposure HDR

Dinner Diary - Coconut Cake

SUGAR!!!!
Who loves Sugar ... i love sugar. As a result i was over the moon when i discovered this one. It's essentially sweetened grated coconut inside a bread like bun, deep-fried. Totally awesome, however a tad expensive, weighing in 10000 Dong (US$0.50) each.

Dinner Diary - Banh Xeo


Today's dish was Banh Xeo. This dish consists of three parts, a deep fried Pancake/omelette with bean sprouts, pork, and spring onions, a salad of lettece and mint and some other mysterious vegetable, and Rice paper. The sauce in the bottom right of the image above is fish sauce is a couple stray mint leafs. The glass used to contain Ca phe sua da (lit. coffee milk cold)

The lady at the restaurant (yeah, i didn't eat on the street, i was surprised too), informed me that the proper way to eat the dish was to tear off a piece of the pancake, add some salad, and roll it in the rice paper, and then dip it in the fish sauce (see below).

"They see me rolling"
Ready to go, not before dipping in fish sauce of course
 Once we've rolled up, we dip it in the fish sauce and enjoy. The portion size is surprising big, and the end result is a filling meal. In many ways it reminded me of my favourite dish so far in Asia, Roti Canai. The price however is astronomical in comparison, with Bahn Xeo costing 25000 Dong (US$1.25/£0.75), while the infamous Roti Canai could be had for as little as £0.20. However either way you cut it, it's good.

Wednesday, February 22, 2012

Dinner Diary - Vietnamese Market surprise


Yet another trip to a market, and yet more food that i have no clue about. This dish was contained  rice, tofu, shrimp, chicken, beansprouts, green beans, loads of fish sauce and other assorted veggies.

I think this was a slightly more "natural" dish, where it has no real name, but is just an assortment of good food thrown together on a plate.

Total cost 30 000 Dong (US$1.50/GB£1.00) including some vietnamese tea.