Objective-C
iOS Developer Tips - Visitor Stats:
|
|
|
Objective-C Comment Styles
A few weeks ago I wrote about Objective-C Indentation Styles. A reader (thanks Joe) commented and suggested a similar post that covered comment formats. That blog post follows… Interface File Comments When I create an interface file, here is the basic layout of my comments: /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * AboutViewController.h * * Created by John on 6/10/11. [...]
Objective-C Indentation Styles
Discussions with developers about their preferred indentation style often seems to stir the same passion as one’s preference for beer, wine or cocktails. This post isn’t as much a tip or trick, as it is an opportunity for developers to share their variations and preferences when it comes to indenting code. Let me give you [...]
Introduction to Blocks in Objective-C – Part 2
In the first post on blocks, Introduction to Blocks in Objective-C – Part 1, I covered the basics for creating block variables, working with __block modifier and using typedef to define blocks. In this post I will show how you can pass a block as a parameter, use enumeration with blocks, as well as take [...]
Introduction to Blocks in Objective-C – Part 1
Beginning with iOS 4.0, Apple introduced blocks, which look and operate much like C functions. However, blocks offer many interesting capabilities beyond functions as you know and love them today. A block is really nothing more than a chunk of code. What makes them unique is that a block can be executed inline as well [...]
Using the @class Directive
The @class directive often seems to be a point of confusion. Let me try and provide a little insight. The @class directive sets up a forward reference to another class. For example, in the code below the reference to @class HomeBrewRecipes informs the compiler that HomeBrewRecipes is indeed a class, so when the compiler gets [...]
The Basics of Protocols and Delegates
Apple offers a good overview of working with protocols in their Objective-C Programming Reference. However, sometimes a simple working example can go a long ways… Introduction Protocols can be helpful in a number of scenarios, a common usage is to define methods that are to be implemented by other classes. A familiar example is when [...]
Fast Enumeration on the iPhone
With the introduction of Objective-C 2.0, you can now iterate through collections (arrays, etc) with ease using a language feature known as Fast Enumeration. This enumeration is both faster than using NSEnumerator and is also much more concise as it relates to the syntax, resulting in code that is easier on the eyes.
Specifying Simulator Only Code
There are times when you need to write code that is only applicable when working with the simulator. As an example, I was recently working with an application that required the user to take a picture with their iPhone. Once the picture was taken the application was to show the image to the user, at [...]
Of BOOL and YES
It may not be immediately clear that the Objective C BOOL "type" is not actually a boolean type at all. This is a legacy from the original C language, which does not have an intrinsic boolean type (the iPhone GCC C compiler supports the ISO C99 standard which does define a bool type). To clarify, [...]
Class Variables
I previously wrote about the lack of support for private methods when working with Objective-C. As part of that post I presented a few work-arounds. Along the same lines, there are is no support for class variables in Objective-C. This post will explore this a little further and walk through a short example that shows [...]
Objective-C Object as a C Structure
Okay, so figuring out how to unwind an Objective-C object into its base representation goes against all that is object-oriented programming, however, it’s interesting none-the-less. In Objective-C there is a directive, @defs(), that outputs (at compile time) the list of instance variables for a class. We can use this list to create a C structure [...]
C++ on iPhone: Part 2, Exceptions
In part 2 of this C++ on iPhone series I’ll be exploring C++ exception handling support, and as a bonus I’ll touch on use of standard C++ lib console output stream, as well as showing a way to call C++ code from Objective C. As a reminder, exception handling is normally one of the weak [...]
Java Developer’s Guide to String Constants in Objective-C
It is my experience that, when developing a J2ME application, excessive String creation is often the leading cause of memory “leaks”. There is always that step during the development cycle where you go back over all your code and refactor out any strings that should be defined as constants. This is no less true of [...]
Java Developer’s Guide to Static variables in Objective-C
The concepts of “static” variables are different in Objective-C compared to Java. That does not mean, however, that the concepts do not exist. Consider the following common uses of ‘static’ in Java: public static final int MY_CONSTANT = 0; // Constant public static String MyVar = “Foo”; // Class Variable In all of the above [...]
A Java Developer’s Guide to Threads on iPhone
Java makes it ridiculously simple to run code in threads and ensure that your objects are thread safe. When developing user experiences, threads enable you to do things in the “background” (like downloading and parsing content) without rendering your application unresponsive and giving the user the sense that the application may have “frozen”. The value [...]






