Skip to content

Recent Articles

6
Apr

iPhone Memory Management – Part II

More examples as I work through the project I’m reviewing:

Case: Auto-release on instance variables

When assigning to an instance variable, you should not set the object to autorelease. By having an instance variable means you want to ‘hold on’ to the object. And, make sure you do a release in the dealloc function for each instance variable that you have.

myObj = [[Obj alloc] init] retain]; //This is an instance variable

- (void)dealloc {

if (myObj) [myObj release];
[super dealloc];
}

Case: Assigning to properties

As a follow-up example, sometimes your instance variable are ‘linked’ as properties. If you set your instance variable through a property, you need to pay attention to your property attributes. If your property says retain, don’t retain again.

In ClientClass.c

….

Obj *myObj;

}

@property (nonatomic, retain) Obj *myObj;

In ClientClass.m

self.myObj = [[Obj alloc] init];  //No need to retain. The setMyObj function takes care of that.

3
Apr

iPhone Memory Management – Part 1

In review of a project today, I realize I need to write down some general rules on memory management around Objective-C.

I’m going to write more on this but here are some general rules:

Case 1. Setting properties.

Obj *obj = [[obj alloc] init];

myClient.obj = obj;

[obj release];

This assumes the property is either retain or copy. Either way, it’s the receiver’s responsibility to make sure the memory is being retained.

Case 2: Returning obj

- (Obj) foo{

Obj *obj = [[[Obj alloc] init] autorelease];

return obj;

}

When sending an obj as return, always set it to auto release. This is basically the same principle as “Clean up after yourself”.

Case 3: Array Manipulation

Sometimes you need to create a Mutable Array, populate it and return an Array. What I recommend is the following:

- (NSArray) foo{

NSMutableArray *tmpArray = [[NSMutableArray alloc] init];

… Build the array.. read from the database and populate it, etc.

NSArray *rtnArray = [NSArray ArraywithArray:tmpArray]; //This is an autorelease copy.

[tmpArray release];

return rtnArray;

That’s the basic cases I have in mind right now. I will continue to write as I come across them this weekend.

26
Mar

iPhone SDK Training

Since I started training my staffs on iPhone development, I thought may be it’s time to restart my teaching profession (I built a Java training school back in 2002). So we will start offering a 3-day crash course on everything iPhone soon. Here is the description:

================================================================

PD401 Jumpstart iPhone Development

Designed for people with prior programming experience such as C, C++, Java, C#, or Visual Basic, this compressed course provides a fast track to the iPhone SDK. Students will learn the basics in the Objective-C language and how to develop native applications for the iPhone and iPod Touch. Objective-C fundamental will be covered for students to quickly transfer their knowledge from other languages. Various iPhone SDK frameworks will be covered in details with hands-on examples.

Upon finishing this course, you will have a comprehensive understanding of all the major frameworks in the iPhone SDK and will be able to start developing on the iPhone platform immediately.

Note: Most iPhone training course on the market is a port from an existing Cocoa course for the Mac desktop platform. This course is built from the ground up with iPhone focus. The only goal is to let you being on this exciting platform as soon as possible.

At the end of the course, students will take home 4 complete fully functioning applications.

Framework covered:
- Core Location (GPS)
- Multi-touch Gesture
- Acceremormeter input
- Audio Recording
- Photo Capturing
- Quartz 2D graphics
- OpenGL 3D graphics
- Audio and Video
- SQLite

Class Outline:
Session 1:     Objective-C, Cocoa, Coca-touch fundamentals. Objective-C classes, memory allocation, language conventions.
Session 2:    Setup development certificate and mobile provisions for deploying on the device.
Session 3:     Building View based application with Interface builder. Standard UI widgets. View Controllers and View transitions. iPhone UI design strategies.
Session 4:     SQLite, UITableView and custom TableViewCell,
Session 5:    Core Location, Google Map integration
Session 6:    Server integration with HTTP, FTP. Integrate with Php and Ruby on Rails servers with XML-RPC.
Session 7:     Multi-touch Gesture. Accelerometer input, shake and movement detection.
Session 8:    Mutli-media. Audio and video, Audio Recording, Photo capturing
Session 9:    Graphics. Quartz2D animation and OpenGL3D animation
Session 10:     Prepare application for upload to the App Store and tips in dealing with the Apple approval process
=============================================================

26
Mar

iPhone development: Web or SDK

Came across an article from Ian Thain.

Web or SDK?
— Web Development and SDK Development each offer distinct advantages to the iPhone Developer…So I set out over the last two months, with the aid of the LinkedIn Polls feature to gauge the trend

I am a true believer of native application. After so many years of working on write-once-run-anywhere, I’ve come full circle (twice, actually) that if you want to develop for a particular platform, you should take advantage of all the features from a platform.

This is also why the iPhone come in late and now are far ahead of WindowsMobile. Windows has been in the mobile business for over 10 years and yet it failed to capture the market. Why? Because they tried to build an OS that will run on all the phones out there.

So now I take device agnostic very differently. As app developers, our goal is to provider users with the best experience. If I build a UI that will be ‘translated’ to different devices, the end result is that it doesn’t feel right in some device. For those who have done serious mobile web development, you will understand even web app will need to be tuned for each device, resolution, browser, OS, etc… So if someone tells you that you can develop the app once and it will work nicely on all platforms, either they are not telling the truth or the end result is not good.

That said, other than the UI, everything else should be platform neutral. Rather than trying to make the UI generic (which is impossible), we are creating a set of control functions that are common across all platforms, so device agnostic to us is common data (through XML), common behavior (through Restful webservices) and native UI.

Now am I saying everything should be native and never web? Of course not. web is great because it’s flexible, easy to develop, easy to deploy and provide real-time information to the users. Now when we design new app, we always starts with the final user experience, that always lead us to building native app with some web widgets inside for real-time dynamic updates.

15
Jan

Inauguration Report hits the App Store

Dave called me back to help out on the Inauguration Report project a week ago. I am so proud of the fact that I got to participate in the Twitter Vote Report project and now the Inauguration Report project.

This time you can report text, audio and photo. And also utilize offline storage so if cell coverage is affected during the Inauguration, reports can be submitted later.

Check out the App here:

http://www.zerionconsulting.com/inauguration_report.html

Download from App Store:

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301986752&mt=8

Don’t forget to also checkout our game Rochabeau:

http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=300203402&mt=8

3
Nov

Another Report View

2
Nov

Virginia Vote Report

2
Nov

More Twitter Vote Report Video

2
Nov

Twitter Vote Report Video

Twitter Vote Report

31
Oct

Everbody should Vote and everbody should Report!

On November 4th 2008, millions of Americans will go to over 200,000 distinct voting locations and using different systems and machinery to vote.  Some voters will have a terrific experiences, and others will experience the same problems we have been hearing about for years – long lines, broken machines, inaccurate voting rolls, and others will experience problems that we haven’t heard about before. That’s why a new citizen-driven election monitoring system called Twitter Vote Report (www.twittervotereport.com) was just launched. Using either Twitter.com, iPhone, direct SMS, or our telephone hotlines, voters will have a new way to share their experiences with one another and ensure that the media and watchdog groups are aware of any problems.

And YOU can help!  Be a citizen journalist!  Submit a report about conditions at your polling place.

Four ways to submit reports to Vote Report:

  • Twitter: include #votereport and other tags to describe the scene on the ground
  • SMS: Send text messages to 66937 (MOZES) starting with the keyword #votereport plus other hash tags
  • iPhone: We have a Twitter Vote Report iPhone app in the App store!
  • Phone: Call our automated system at 567-258-VOTE (8683) to report about conditions, using any touch-tone phone

And if you would like to talk to a human to report bad conditions you’ve observed, please call our partner 1-866-OUR-VOTE.

As news outlets and blogs will report on Election Day stories, www.twittervotereport.com is an invaluable resource for thousands of voters to get immediate help. From questions like “where do I vote” or “how do I make sure that my rights are being upheld,” Twitter Voter Report augments these efforts by providing a new way for voters to send text messages (aka tweets) via cellphones or computers which will  be aggregated and mapped so that everyone can see the Nation’s voting problems in real-time.

Imagine a nationwide web map with pins identifying every zip code where Americans are waiting over 30 minutes to vote or indicating those election districts where the voting machines are not working. Collectively we will inform each other when the lines are too long and ensure that media and watchdog groups know where problems exist.

For more information, go to www.twittervotereport.com.  The complete list of tags or keywords that you can include in your reports is listed there.   And please help to spread the word — send this to everyone you know!