Tag Archives: iPhone

Learning web programming for iOS

6 Jul

Learning new stuff is always hard, but rewarding.

The problem is that I’m using old technology and in the fast moving mobile devices market that is a bad thing. Apple’s iOS SDK requires Snow Leopard (SL), and because Leo Laporte didn’t think there’s a compelling reason to upgrade to SL for the general user, I still haven’t. I guess now there is a good reason, iOS4. The current SDK I’m using still codes for iPhone OS 2.

Now you may wonder why this would be a problem if I’m trying to create web applications. Well, the handy Dashcode applications that comes with the iPhone SDK assumes you use technology of that SDK. Of course, you could do everything in a text editor, but my intention is to create some kind of workflow comics creators will be comfortable with, so a visual editor, at least for the visual design part, is crucial.

So which parts are essential for any web application?

Well, any web app is a purpose-built regular web document that consists of 3 parts:

  1. HTML
  2. CSS
  3. JavaScript

HTML stands for HyperText Markup Language and contains the information (text and images) of a document, plus its markup. CSS stands for Cascading Style Sheet, which describes the appearance of the document (layout) and general user interaction. JavaScript is the programming language that specifies how the document will interact with the user. The markup in the HTML document integrates all three parts.

Now it’s hard to do all three things (information, appearance, and interaction) at once, so you typically do them separately (and in order: information first, then how it looks, and then how it “feels”–user interaction). The information part is mostly either created by humans and/or collected in external databases. It requires creative thinking for the most part. The appearance can be made easy with a visual layout editor like Dashcode. The user interaction can be hugely simplified by using a library of code, a so-called framework. The most used JavaScript framework for web applications is jQuery.

So I can see five areas where I need to improve my knowledge and skills:

  1. HTML
  2. CSS3
  3. Dashcode 3
  4. JavaScript
  5. jQuery

Not all at once, of course, but rather as you need it. Luckily, most of the knowledge and tutorials are freely available on the web.

PS I expect to receive a copy of Mac OS X 10.6 (Snow Leopard) this week. I’ve just ordered it while I’m adding this.


iPhone versus Droid

29 Oct

Who is going to win, stupid iPhone or lame Droid?

iPhone vs. Droid

That is all.

Passing an array to a function in C

17 Aug

Yes, I admit it. I too have fallen for the iPhone, iPhone programming to be more specific. At this moment, aside from improving my drawing skills, I’m also brushing up my C programming skills, using the (out of date) book “Beginning Mac OS X Programming”. If you’re not into programming, just skip this blog post.

Here’s the problem. In the C language, how do you pass an array to a function, manipulate it and return it as an array value? The problem seems to be that if you use sizeof to determine the length of the array, that length isn’t known at compile time. The content of the array may change while the program runs. So the best practice seems to be to determine the length of the array before you call the array function, and pass the length along as well.

Here is the code to demonstrate my point.


// Prototypes
void printArray(int ar[], int n);
int* revArray(int ar[], int n);

int main (int argc, const char * argv[]) {
int ar[] = {1, 2, 3, 4, 5, 6, 7};
// sizeof gives size in bytes
int n = sizeof(ar) / sizeof(int);
printArray(ar, n);
printArray(revArray(ar, n), n);

return 0;

// Print all array elements.
void printArray(int ar[], int n) {
for (int i=0; i < n; ++i ) printf("%d ",ar[i]); printf("\n"); } // Reverse array elements. int* revArray(int ar[], int n) { int v, j; for (int i=0; i < n/2; ++i) { j = n - i - 1; v = ar[i]; ar[i] = ar[j]; ar[j] = v; } return ar; }[/sourcecode] I tried this code without passing along the length of array ar. I tried to determine the array length within the called function instead of in the part of the code where the array was defined (in this case, main). That didn’t seem to work. After Googling in vein, I looked it up on Stack Overflow (which is, by the way, the best resource for questions about programming on the Net). And there was the answer, as I just told you. Well, actually it was a question about C++, but who’s counting? Still the explanation in the answers were a bit puzzling, so I tried some reasoning.

Here’s what I think is happening.

In C you pass parameters to a function by value only. In case of an array, the value of a pointer to the array is passed. This value is used to initialize the pointer that was defined in the function parameter list. Apparently, C has no means of passing the length of that array as well.

In fact, you only pass the pointer to the first array element to the function. The function cannot know how many elements follow after the first element, so the function caller has to tell the function, by passing the value of the length of the array.

Of course, in main the array ar is in context, so sizeof(ar) will give you the number of bytes that is reserved for ar. If you divide that by the number of bytes that is reserved for an int value (which you write in C as sizeof(int)), you have the number of array elements in an integer array.

That is all.