On Apr 9, 6:58 pm, scphantm <[email protected]> wrote:
> bossman has me working up a plan for an IPhone app that hooks into our
> existing system using our web service interface.  has anyone worked
> with objective c before?  is it like c++ and c in the aspect of having
> to deal with memory management and garbage collection by myself or are
> their systems in the iphone api that deal with that.

Objective-C on the iPhone has semi-automatic memory management.  You
don't do "malloc()" or "free()", like in plain C.  Instead, you send
an object the "retain" message if you want to hold on to it beyond the
current execution, and then "release" if you're done with it
(Objective-C has messages instead of methods, which means you never
get a NPE since the Objective-C runtime ignores when you send messages
to a "nil" object, and you can also deal with messages for which there
is no implementation, such as finder methods in Hibernate / Grails).
It's semi-automatic since there's a "auto release pool" which is
called after the main threads returns to painting the UI, so if you
send a "autorelease" message to an object, it will be garbage-
collected until somebody else sends it a "retain" method (e.g., you're
adding a label to the current view, then you'd send the label an
"autorelease" but the view will send it a "retain").  This came back
biting me a couple of times - if you see a "BAD_ACCESS_ERROR" (or so)
in the debugger (it'll automatically stop even if you don't debug, and
you can check out the stack trace), then it's typically because you
didn't retain an object, so it's gone, but you still send it a message
and now something else / crap is at the address.

Overall, I found Objective-C to be better than Java in some respects:
optional typing, messages instead of methods, properties, function
pointers, you can add methods to any existing class (I think it's
called a category - a regular expression library I use adds its
methods to the built-in string class), emphasis on immutability for
collection classes (there are different types for mutable and
immutable ones), simple concurrency is easier than in Java (IMHO),
reading from a URL or a file is a single method call on the string
class etc.  Some areas are worse: only semi-automatic garbage
collection (Mac OS X has fully automatic one), overall the language is
more verbose and some other things I forgot right now.

But where the iPhone really shines is in the frameworks you get - you
can easily build apps that use the iPhone quite a bit (video, sound,
animation, map, email, web browser), and you have a number of
persistence options (a "JPA-lite" framework with a graphical entity
relationship diagram designer, simpler "class serialization to a file"
and "key value pairs in a file" .  Except for some areas (lower-level
sound and video APIs, address book), all of them are Cocoa Touch
Objective-C APIs with consistent patterns (delegates).  You get two
different profilers (one "memory/CPU in your app" one, one for how
much time/CPU cycles you spend in OS calls), a good UI builder
(Interface Builder) and a acceptable IDE (XCode).  Auto-completion is
stronger in XCode, but overall I think it's weaker than Eclipse (no
tabs for what I can see, less refactoring, no Mylyn for only showing
you the relevant code, only CSV/SVN integration).  Their SDK docs
rock, you get a ton of guides and samples you can run in XCode with
one click, full text, type-ahead search across all docs and PDF
versions of all guides - the JDK docs are lousy.  Finally, the
simulator is very good, debugging on the device and the simulator is a
breeze, only getting the app to run on your phone can be tricky (it's
certificates and profiles and stuff).

I would recommend the Stanford iPhone class in iTunes U (if you can
watch them on a commute) and this Prag Prog book:
http://pragprog.com/titles/amiphd/iphone-sdk-development  And of
course, http://stackoverflow.com/ is your friend.  :-)

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to