Pointers in Objective-C

Objective-C is a strict superset of C. That means every feature of C is alive and kicking in Objective-C, pointers included. Five years of pointer free programming has made me…rusty. As the saying goes, “There is no better way to learn than to teach”.

1
2
3
4
5
6
7
8
9
10
int a = 2; //Your standard variable
int *b = &a; //An integer pointer

//Prints "The value of a is 2"
NSLog(@"The value of a is %i.",a);

*b = 3;

//Prints "The value of a is 3"
NSLog(@"The value of a is %i",a);

This is your standard pointer example. int *b is an integer pointer that we are assigning the address of int a. The asterisk * is generally called the dereferencing or indirection operator and means “Give me the value stored at the address this pointer points to”. The & operator means “Give me the address in memory that this variable is stored at”.

What can often be confusing is that with one line declaration and initialization short-hand, the asterisk is not performing any dereferencing but is actually simply declaring that this is an integer pointer.

1
2
3
4
5
6
int *b = &a;

//..is the same as 

int *b;
b = &a;

This snippet of code illustrates how this actually works in memory.

1
2
3
4
5
int a = 2;
int *b = &a;

NSLog(@"%p -> %i",&a, a);
NSLog(@"%p -> %p",&b, b);

The output:

<em>0x7fff5fbff88c -> 2
0x7fff5fbff880 -> 0x7fff5fbff88c</em>

left number: the variables location in memory. right number: the value it stores.

Remember a pointer is like any other variable, it has its own location in memory but its value is simply another memory address. So when you write “*b” you are saying “Give me the value (2) stored at the address (0x7fff5fbff88c).

Pointers to Pointers

With pointers to pointers things get a little more complicated. A pointer can actually point to another pointer. Take the following code.

1
2
3
4
5
6
7
int a = 2;
int *b = &a;
int **c = &b; //A pointer to a pointer

NSLog(@"%p -> %i",&a, a);
NSLog(@"%p -> %p",&b, b);
NSLog(@"%p -> %p", &c, c);

The output:

<em>0x7fff5fbff88c -> 2
0x7fff5fbff880 -> 0x7fff5fbff88c
0x7fff5fbff878 -> 0x7fff5fbff880</em>

int **c points to int *b which in turn points to int a. To further illustrate the following examples show how we can reference the same thing in multiple ways.

a == b == **c; //The value 2 &a; == b == c; //The address of a or 0x7fff5fbff88c

Pointers to pointers have practical uses in Objective-C when a method actually needs to return multiple values.

1
2
3
4
- (BOOL) printNumber:(int)number error:(NSError **)errorPtr;

NSError *anyError;
[myClass printNumber:&anyError]

printNumber in this case can return a BOOL with the standard return statement and an optional error by setting our *anyError pointer to a new NSError object.

For example a sample implementation of printNumber:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (BOOL) printNumber:(int)number error:(NSError **)errorPtr
{
    if(number < 0)
    {
        NSError *newError = [MyErrorFactory newErrorWithDesc:@"Negative numbers are not allowed"];
        *errorPtr = newError;
        return NO;
    }
    else
    {
        NSLog(@"Your number is %i",number);
        return YES;
    }
}
Tech

Southeast Asia Travel Tips

Christina and I left for Southeast Asia on March 6th. We flew back home on November 12th.  At just over eight months of travelling you start picking up on what does and doesn’t work.

Packing

  • Pack light. No seriously pack very light. Budget airlines in Asia have very strict weight limits for baggage. 

  • For men use underwear like these that are quick drying and can be washed and dried overnight in a hotel room. I survived on 3-4 of them.

  • Favor clothes made from a quick drying material. Cotton takes a long time to dry in a humid climate.

  • Bring a laundry bag to keep your dirty clothes in.

  • Bring gallon sized zip-lock bags. If some of your clothes do get wet, it helps keep the rest of them dry.

  • My backpack was a 70L Osprey Bag. It only just fit on an overhead bin. Consider a slightly smaller bag.

  • Laundry can be done on the road fairly inexpensively. On average we paid $1/kg. An average weekly load for the two of us was 3kg. Expect hand washing and hang drying. Dryers are exceedingly rare. Usually took 1-2 days for clothes.

  • I survived on one pair of trekking shoes and one pair of flip-flops.

  • Sarongs may not be the most manly things but they are invaluable. Mine has acted as a towel, a bed sheet, a scarf, padding for my camera to name a few. You can get them for cheap everywhere in Southeast Asia.

Accommodations

  • You can stay dirt cheap. Especially if you are OK with dorm style.  Even if you are not a private room can be had for $10 or cheaper in most places.

  • You do however get what you pay for. Expect to pay more for each amenity such as hot water and air conditioner.

  • During a particular area’s high season finding a budget room can be stressful. Also more expensive.  For example we were in Indonesia during high season and struggled to find anything for less than $20/night on the Gilis.

  • A lot of budget places do not provide top sheets or a blanket, towels, shampoo/soap or toilet paper. Which reminds me, always have a toilet paper roll in your day bag.

  • Many of the best options do not have a web presence. So don’t expect to be able to book everything on Agoda.com or booking.com. Sometimes you just have to show up and look at your options in person.

  • In general if we felt uncertain about a place (i.e there is no well known backpacker’s area in a big city) we would book the first two nights via Agoda.com and explore other options while there.

  • Squat toilets are common in muslim areas.

  • A tasting of some of our accommodations:

Travel

  • Obviously it varies from country to country, but in general it is very easy to get from place to place.

  • Buses are almost always the cheapest option. Buses vary in range from luxurious recliners to “oh my god get me off this thing”. Safety is not a top priority.

  • In general when booking with a large bus liner prices are non negotiable. When booking with small tourist agencies prices are always negotiable.

  • Budget airlines are WAY cheaper than flights in the USA. Jetstar/ValuAir is to be avoided at all costs. Tiger is hit or miss as is Lion Air.  AirAsia is the by far the best.

  • Philippine Airlines deserves its own bullet point for being the very worst run airline I’ve ever been on. Seriously, get your act together guys.

  • Budget airlines will nickel and dime you to death. Sure the base price may be $30, but it costs another $30 to check a bag and $8/person to pay by credit card (no joke).

  • Most of the airlines have a combined weight limit of 7KG for carry on. On all but one flight (darn you Singapore Airport) we got away with bringing our 15KG/person of baggage on. Check in online, be friendly and act like your bags are light as a feather every time you see an employee.

  • We bought almost all of our flights 2-3 days prior. Some we bought the night before. Budget airlines seem to play less pricing games.

Money

  • If you have time, sign up for a Charles Schwab Online Checking Account for no foreign ATM fees. 

  • The best exchange rate is almost always via an ATM machine or via credit card (90% of places will not take credit cards though or will charge an additional 5%, so don’t count on it).

  • Unfortunately most smaller merchants won’t accept the large bills ATM machines spit out. Find a 7-eleven and buy a bottle of water to break your bills.

  • Some smaller locations (and all of Myanmar) do not  have ATMs so plan accordingly.

  • Being overcharged simply because you are a westerner is common. Try to figure out (by talking to people, hotel staff are a good place to start) how much things should cost.

  • I always carried $100-200 in USD just in case I couldn’t get to an ATM or the only one on the entire island breaks (I’m looking at you Gili Air).

General Advice

  • Smile. Be friendly. You will have a far more enjoyable time and people will be far more welcoming.

  • Do not lose your temper or show your frustration. There will be many, many times when it is easy to do both. Simply smile and walk away.

  • Very few prices are not negotiable. More often than not the same exact thing can be bought from 10+ vendors. Negotiate and shop around.

  • Be super friendly and joke around with the merchant when negotiating and remember they will tell you anything to get you to fork over you money. Be polite but take everything your told with a grain of salt.

  • Don’t buy from children. Doing so only encourages child labor and keeps them from school.

  • Embrace cultural differences rather than becoming irritated by them. It sounds easier than it is.

  • Customer service is non-existent so don’t expect much. Tipping is rare.

  •  Try to space out your mainland and beach trips. Two months straight on a beach might sound appealing, but I promise you that after 3 weeks you will be begging for big city amenities.

  • Plan minimally. For each new location I briefly browse www.wikitravel.org. It helps to be aware of the scams of the day, the best transport options and where you are likely to find budget accommodations.

  • Try to get off the beaten path. If you stick to the touristy areas you will miss the best parts of travelling.

  • Be flexible. There are places we planned on staying one day but loved it and stayed 4. There are places we were disappointed with and left early.

  • Get travel health insurance with emergency evacuation coverage. Its cheap and worth every penny (hint: remove trip cancellation coverage and see your policy half in price).

Travel

Naturally, Kenya

Buffalo among the flamingos in Nakuru Park.

Cheeky Baboon stealing from the litter bin.

Chicks at sunset.

Nakuru park becomes more and more flooded each year.

What once was a road in Nakuru National Park.

Giraffe on the move. Nakuru National Park.

Cyclist in training.

Local children in Lwalla.

Taking in Lwalla's countryside.

There is a ton of livestock.

Woops. Graffiti in Hell's Gate.

Fallen tree in a dried riverbed, Hell's Gate.

Obama Lollipop. They love him and everyone claims to be related to him.

A Rock Hyrax in Hell's Gate.

Warthog. Nakuru National Park.

Zebra in Hell's Gate.

A baby lamb and his momma.

Biking through Hells Gate.

Blood: Water Mission

General, Travel

Charming, Myanmar

Myanmar. Oppressive Government. Remarkably friendly and welcoming people.

Two weeks before our scheduled arrival Myanmar was struck by 5 separate (minor, but still) bombings. I am so glad we did not cancel (although we almost did, numerous times).

Myanmar truly is largely unaffected by tourism and that is a fantastic thing. Take stunning natural beauty, throw in delicious food, millions of smiling faces genuinely happy to have you and you have one heck of a place to visit. Highly recommended.

Say Hello....

Fisherman demonstrating the burmese 'row' with one leg.

Scaring the fish into your net.

Lakefront property.

Floating house in the middle of Inle lake.

The famous traditional fisherman of Inle Lake.

Waiting for the boat races.

Traditional boat races.

Temples on Inle Lake.

Temples as far as the eye can see in Bagan.

The temples of Bagan.

Shwedagon Pagoda

It makes for a great picture.

Everywhere you go the children beg to have their picture taken.

Flying a kite seems to be the popular form of entertainment.

Cows taking it easy Nyaungshwe.

Our boat captain for the day on Lake Inle.

Ferry on Lake Inle.

Travel

Siem Reap, Cambodia.

If there is one thing I regret about our 8 month trip throughout Southeast Asia, its that we didn’t spend more time in Cambodia.  The temples of Angkor truly are astounding. The people are extremely friendly. The food is delicious. Everything is highly affordable.

Angkor Wat at Sunrise.

Walkway around Angkor Wat.

Traditional dance at Angkor Wat.

The faces of the Bayon.

The Bayon Temple.

The details in every wall are astonishing.

The famous Ta Prohm

Taking a nap.

The entrance to Angkor Wat, as seen form Angkor Wat.

Moss covered temples of Angkor.

Laboring in incredible heat.

Fishing for a big one.

Never ending doorways.

All they wanted in return was candy.

Long walk home.

No caption required.

The temples are stunning.

Travel

Thailand. Well Touristed.

I’m just going to be up front about it. Thailand was my least favorite of the 8 countries we visited in Southeast Asia. It is the most touristed (which has its perks though when you are looking for some western amenities), had the least friendly people and the most scams. It did however have some of the best street food and local beer.

The number of scams force you to constantly be on guard making it hard to relax. I was lied to multiple times, approached by scammers/hawkers constantly, double charged in taxis and overall felt the least welcomed by the locals.

That being said there is a lot to do in Thailand and you can do so cheaply thanks to well developed infrastructure. For those into shopping, it can’t be beat.

Granted I have heard numerous people say the same about Vietnam, a country I loved. I am sure living there for 5 months has made me somewhat biased and perhaps I was simply unfortunate in my overall experience with Thailand.

Catfish on a stick.

One of over 200 temples ("Wat") in Chiang Mai. in Chiang Mai.“)

Monks in Thailand are revered.

Street Food in Chiang Mai. Delicious.

Siam Square.

Infamous Khao San Rd, Bangkok.

Guarding the temple for centuries.

The Grand Palace, Bangkok.

Taking in the flower market in Bangkok.

Gold flakes being places on Buddha.

The famous elephants of Thailand. I prefer the stone ones that cannot be mistreated.

Dragon Temple Architecture. A common theme in Thailand.

Chiang Mai Old City Wall.

Tuk Tuk in Bangkok.

Travel

Palawan, Philippines

Palawan was one of the highlights of our 9 month SE Asia journey. Some of the most stunning scenery, friendliest people and for the most affordable prices. The people are seriously friendly (Port Barton gets the nod for the most friendly people of our entire trip). Fresh seafood is abundant. Our favorite meals were fish caught 5 minutes prior and cooked on a tiny grill on the stern of the boat. The surrounding islands of Coron are the most beautiful I have ever seen.

Puerto Princesa is the main point of entry into Palawan. An energetic city on the rise. Getting to Port Barton during the rainy season….good luck.  One of our favorite places, ever. We thought El Nido had the most amazing islands anywhere….until we went to Coron.  Diving inside japanese shipwrecks? Check. Crystal clear freshwater lakes? Check. Crystal clear reefs? Check.

Coron Island.

The rock formations are stunning in Coron.

The islands of Coron.

Kayangan Lake. "The cleanest lake in Asia"

Green Lagoon, Coron.

Lazy Sunday Afternoon.

Tricycle in Puerto Princesa.

The bay of Port Barton.

Blowing bubbles in Port Barton.

Port Barton. All accommodations are right on the beach.

Adorable.

Long distance transport in Palawan.

Neptune Diving's Bus.

Fresh Sea Urchins.

Fresh Parrot Fish and Prawns.

Children playing on the dock in Sabang.

Underground Cave in Puerto Princesa.

Travel

Journey Through Malaysia

Food. Varied, delicious food. This is what I will remember about Malaysia. The food courts (different than food courts we know in the US) are teeming with options. Indian, Chinese and Malay all simmer together to create a hodgepodge of deliciousness. Most dishes for under $2.

Our trip to Malaysia was short at just 2 weeks but we were able to cover quite a bit of ground.  We started in Langkawi, headed to Penang, and finally crossed over to Malaysian Borneo (Kuching).

Langkawi was a beautiful island retreat, Penang a teeming city with more than enough options for the tourist, and Borneo was a nature lover’s dream.

Ants in Bako Park. Miles of ants.

Bako National Park entrance.

The famed cobra of Bako National Park.

The waterfall we walked 6km to reach in Bako National Park.

The Camera Museum in Penang.

Langkawi from the top of the Cable Car.

Langkawi Sky Bridge.

I'm thinking of quitting my day job.

A food court vendor in Penang.

Penang Heritage Walk.

The Moustache Houze. Closed unfortunately.

Guarding his temple.

Semenggoh Orangutan Kuching.

General

Labuan Bajo, Indonesia

Labuan Bajo is the main launching point for excursions to Komodo National Park. There is a tiny airport a few KM from town (walking into town took us about 50 minutes, not recommended during the heat of the day). The town itself has little draw other than a place to stay and grab a meal. Following the trend of Bali and Lombok during high season expect to pay a lot for a little, especially for accommodations (compared to the rest of Southeast Asia).

The main attraction is the diving/snorkeling/trekking/sight-seeing on the surrounding islands. The scenery is phenomenal, the water crystal clear and the aquatic life abundant. Its a snorkeler’s and diver’s dream.  Seraya island was the best snorkeling I’ve ever done by far.

Labuan Bajo can be difficult to get to but definitely worth the effort. Just keep in mind the expectation that a boat is required for anything of interest.

Labuan Bajo Airport.

Some Komodo Dragons cuddling. Too bad their cannibals.

During dry season...its really dry.

The drop-off is stunning. We snorkeled with a pack of 7 sharks here.

Phenomenal sunsets to be had every night in Labuan Bajo.

The colors. Just amazing.

Seraya Island. Our own private paradise for three days.

A Toilet. A hole into the ocean.

Bintang Beer, my favorite of all Southeast Asian Beer.

Finding a way through the clouds.

Travel

7 Habits of Highly Successful People, 96.05% Too Long.

Date Read: October 11 – 15th, 2013

Direct Amazon Link

I understand that Stephen R. Covey is highy respected and I’m sure he rakes in $5,000+/hour consulting fees but really this book for me still falls into the ‘self help’ genre where most information is common sense and that which isn’t can be found on any ‘self help’ blog for free.

That is not to say I do not agree with the underlying premise of each of the 7 habits. In fact Habit 1 (“Be Proactive”) and 5 (“Seek first to understand, then to be understood”) in particular I think we should all be mindful of every day. Habit 6 is titled “Synergize”, Habit 7 is titled “Sharpen the Saw”. No explanation is needed as to why ‘fluff’ is the first word that comes to mind.

This is how I imagine Covey’s conversation with his publisher after coming up with the idea for the book.

Covey: “I have this great idea for a new book”. Publisher: “Excellent, how far along in the process are you?” Covey: “Finished.” Publisher: “How long is it?” Covey: “15 pages.” Publisher: “What? We can’t sell a 15 page pamphlet for $19.99. Fluff it up!”

1 Month Later:

Covey: “Ok. The book is complete. Still 15 pages of good information, but now with 365 pages of fluff as an added bonus!”

Seriously read this WikiBooks’‘ summary, and save yourself the time and money. Update: Even better read this Forbes’ Summary.

Note: This post is part of my 26 Books in 26 Weeks Goal.

Books