A potential gotcha


I wanted to share some interesting artifacts of using the Kindle reader for Mac to read the book while writing code in xcode.

The first is that if you copy/paste from the Kindle into xcode (I don’t recommend doing it this way), the text is pasted in with no line breaks in one jumbled mess. In my opinion it’s much better to type the code in to get used to the environment and making mistakes.


[code]#include <stdio.h> float fahrenheitFromCelsius(float cel) { float fahr = cel * 1.8 + 32.0; printf("%f Celsius is %f Fahrenheit\n", cel, fahr); return fahr; } int main(int argc, const char * argv[]) { float freezeInC = 0; float freezeInF = fahrenheitFromCelsius(freezeInC); printf(“Water freezes at %f degrees Fahrenheit\n”, freezeInF); return 0; }

Aaron, Hillegass (2011-10-11). Objective-C Programming: The Big Nerd Ranch Guide (Kindle Locations 974-978). Pearson Education (US). Kindle Edition. [/code]

The second is if you end up resizing the Kindle app window it may add unintended characters that will cause errors in building. In my case I lessened the width of the page to fit on-screen next to xcode and the Kindle app added a “-” to the text.

This is what the Kindle app showed.

Unintended additional character:

How it should be (by resizing a little wider):

The unintended consequence:


I can attest to the second one. I just finished doing the Challenge in Chapter 5, and I was getting the wrong answer (150 degrees rather than 90 degrees). I finally figured out what the problem was. I was viewing the book in the Kindle App on my iPad in landscape orientation, so that I could see two pages at once. However, I didn’t realise that my font size was large enough to invoke hyphenation in the code samples.

So when I first looked at the Challenge, I saw the line:

float angleC = remainingAngle(-
angleA, angleB);

Couldn’t figure out why was calling the negative of the angleA value, but thought maybe it was part of the exercise. But then I happened to switch to portrait orientation, and lo & behold, the line looked like this:

float angleC = remainingAngle(angleA, angleB);

and when I took the minus sign out of xCode, I got the right answer of 90 degrees, of course.

So lesson learned: if the code sample looks weird, try a different page orientation or font size. This was just enough to throw a newbie like me off for a good couple of hours!


Question: Were you two using the Kindle Application or the Kindle Reader in the web browser?