Programming in Objective-C 2.0

Stephen G. Kochan

Mentioned 37

A carefully written introduction to Objective-C and object-oriented programming for developers new to Mac OS X or iPhone programming.

More on Amazon.com

Mentioned in questions and answers.

Being an aspiring Apple developer, I want to get the opinions of the community if it is better to learn C first before moving into Objective-C and ultimately the Cocoa Framework?

My gut says learn C, which will give me a good foundation.

You can readily enough learn C and Objective-C at the same time -- there's certainly no need to learn the minutiae of C (including pointer arithmetic and so on) before starting with Objective-C's additions to the language, and as a novice programmer getting underway with Objective-C quickly may help you to start "thinking in objects" more quickly.

In terms of available resources, Apple's documentation does typically assume familiarity with C, so starting with The Objective-C 2.0 Programming Language won't be of much benefit to you. I would invest in a copy of Programming in Objective-C by Stephen Kochan (depending on how quickly you want to get underway, you may consider waiting for the second edition):

Programming Objective-C Developers Library Programming Objective-C 2.0 Developers Library

It assumes no prior experience, and teaches you Objective-C and as much C as you need.

If you're feeling a little ambitious, you might start with Scott Stevenson's "Learn C" Tutorial, but it does have some prerequisites ("You should already know at least one scripting or programming language, including functions, variables and loops. You'll also need to type commands into the Mac OS X Terminal.").

(Just for the record and for context: I learned both at the same time back in 1991 -- it didn't seem to do me any harm. I did, though, have a background in BASIC, Pascal, Logo, and LISP.)

Do you want to be a hard-core developer? Then learn c first.

The books you need to completely master c are some of the best writings in technology. Here's what you need:

C Programming Language

The Standard C Library

I'm primarily a C# developer and I've been tasked with "porting" functionality from a few apps to an iPhone app.

The functionality is simple enough, and a language is a language, so I thought, "sure, why not? This will be fun!" ...That is until I got a look at Objective C, which, to me, is ugly bordering on unreadable.

Given that my background is primarly C#, and I'm somewhat familiar with C++, where can I find a good guide tailored to my background to get me moving in Objective C?

The one and only tome I recommend for learning Objective-C for people coming to ObjC from really many backgrounds, is Kochan.

As others have suggested, MonoTouch may be the best option for you. Apple's section 3.3.1 notwithstanding, no MonoTouch apps have yet been rejected from the App Store, and you can always distribute MonoTouch apps through Enterprise distribution if that is your situation. If you don't want to step out of your comfort zone, stick with C#/.Net. That way you only have to learn a new UI framework.

That said, many good developers find that learning a new language is an opportunity to expand their thinking, beyond just being fun. Objective-C has a very interesting history and is (at least) part of the the inspiration for many "modern" languages. Objective-C's stated purpose was to make integrating software components easier, hence its interesting mix of static typing and dynamic message dispatch. Your comments suggest you've taken a rather harsh view of the language. Many of us have the same reaction to any new environment, language, etc. Give it time and you may find that the special features of Objective-C outweigh the "ugliness" you see now.

In terms of learning Objective-C, Aaron Hillegass' book is pretty much the bible. It's OS X-oriented, but you should be able to take the appropriate iOS bits from it. Also, Apple's Objective-C Programming Language guide is very good.

Addition: Think it's worth having a look at this again as a number of new books have/are being released with updates to iOS 4 and the inclusion of iPad programming.

OK, I have read a number of posts regarding iPhone development books, Cocoa and Objective-C. The general consensus seems to lead to one of four books.

  • Kochan's Objective-C book.
  • Hilleglass' Cocoa book.
  • The pragmatic programmers iPhone SDK development book.
  • And Beginning iPhone Development: Exploring the iPhone SDK by Dave Mark and Jeff LaMarche.

I've also added in the following:

  • iPhone Programming: The Big Nerd Ranch Guide

I'm looking for advice on which two to buy in order to get started. I'm looking firstly to get a better understanding of Objective-C. Which two books would compliment each other?

I have a background in Java, with NO Objective-C experience and NO C or C++ experience either.

Firstly, I'd like to get a good idea of the layout and structure of objects and certain data types - obviously it's worth keeping in mind a lot of this will be similar to that of Java. Concepts like pointers and garbage collection are completely new to me.

Programming in Objective-C 2.0 by Stephen Kochan for the foundation, The iPhone Developer's Cookbook by Erica Sadun for additional badassery. I learned more from Erica's book than any other source.

Coming from Java background I am guessing this is expected. I would really love to learn Objective-C and start developing Mac apps, but the syntax is just killing me.

For example:

-(void) setNumerator: (int) n
{
    numerator = n;
}

What is that dash for and why is followed by void in parenthesis? I've never seen void in parenthesis in C/C++, Java or C#. Why don't we have a semicolon after (int) n? But we do have it here:

-(void) setNumerator: (int) n;

And what's with this alloc, init, release process?

myFraction = [Fraction alloc]; 
myFraction = [myFraction init];
[myFraction release];

And why is it [myFraction release]; and not myFraction = [myFraction release]; ?

And lastly what's with the @ signs and what's this implementation equivalent in Java?

@implementation Fraction

@end

I am currently reading Programming in Objective C 2.0 and it's just so frustrating learning this new syntax for someone in Java background.

UPDATE 1: After reading all these answers and Programming in Objective C 2.0 a little further, it's all starting to make sense now!

UPDATE 2: Thanks for the great tip "support-multilanguage". We can combine these two statements into one like so:

myFraction = [Fraction alloc]; 
myFraction = [myFraction init];

Can be reduced to:

myFraction = [[Fraction alloc] init]; 

What is that dash for and why is followed by void in parenthesis?

The dash - means "instance level" ( which is the default in Java ). When you see a plus sign + it means class level ( same as using static in Java )

The void in parenthesis is the return type see below.

Why don't we have a semicolon after (int) n? But we do have it here:

-(void) setNumerator: (int) n;

Because that's the method signature, you can think of it as a interface:

 interface YourClass {
      void setNumerator(int n );// see? semicolon
 }

Same situation.

Objective-C having roots in C ( actually this is the real C with objects ) needs a header file ( completely removed in Java ) where you define what the functions/methods your class would have.

The equivalent if such thing would exist in java would be:

// YourClass.java.h 

 interface YourClass {
      void setNumerator(int n );
 }
 // YourClass.java.m
 class YourClass {
      void setNumerator( int n ) {
       this.n = n;
      }
  }

And what's with this alloc, init, release process?

myFraction = [Fraction alloc]; 
myFraction = [myFraction init];
[myFraction release];

allo-init is the equivalent for new in Java, alloc that's when you ask for memory for your object, alloc request memory, and init calls the init method, equivalent to the Java class constructor ( btw Ruby does the same behind scenes )

There's no equivalent to release in Java because it is garbage collected, in Objective-C you have to release your object.

BTW, the initialization could also be myFraction = [[Fraction alloc]init];

And lastly what's with the @ signs and what's this implementation equivalent in Java?

 @implementation Fraction

 @end

That's the class definition as I mentioned earlier.

I am currently reading Programming in Objective C 2.0 and it's just so frustrating learning this new syntax for someone in Java background.

Here's a related answer that will help you to get more familiar with the square brackets:

Brief history of the "square brackets" is I remember it.

I have developed in C++ many years ago, but these days I am primarily a Java software engineer. Given I own an iPhone, am ready to spring for a MacBook next month, and am generally interested in getting started with Mac OS developmentmt (using Objective C), I thought I would just put this question out there: What Next?

More specifically, what books should I pick up, and are there any web resources that some folks could point me to? Some books that I am planning to purchase:

Anyone familiar with these titles? Finally, I would be very interested in a summary of what I should be prepared to expect, once I embark on this journey. As someone that develops in Java using IntelliJ IDEA, what are some key differences I will notice as I move over to writing ObjectiveC code in Xcode? What's the differences between Mac OS desktop development and iPhone development? Being used to Java garbage collection, what should I know about ObjectiveC garbage collection / memory management. Any other language specific issues that anyone would like to point out? How about building UIs? Is it closer to Swing, building Visual C++ resource files that code interacts with, or is it more like some of the borland IDEs that will generate code for guis?

Having purchased both of the books in your question, I recommend Cocoa Programming for Mac OS X as a quick way to learn the language and the Cocoa framework, and is probably the fastest way to start producing real applications in Cocoa. I highly recommend it. Programming in Objective-C 2.0 is a great reference book, but if you already know C, there's no much it's going to teach you that you can't pick up from the other book. However, if you ever need to a list of all the reserved keywords in Objective-C, that's the book to go to.

All of the user interface can be generated progmatically, but you'll find it much easier to use Interface Builder, which comes with XCode, to lay out the user interface. You'll end up with a lot less code. With bindings, you can even eliminate code which isn't directly related to laying out the interface. The details are in the Cocoa Programming for Mac OS X book.

The one big thing I miss from Java is the collection API. In Cocoa, you just get NSSet, NSArray, and NSDictionary, and there's no analog to the Comparable interface. These classes are also immutable, but have mutable versions such as NSMutableArray.

I actually haven't played with the Garbage Collection in Objective-C 2.0. In previous versions of Objective-C, memory management was handled by the retain, release, and autorelease methods. Objects were created with a retain count of 1. Retaining incremented that count, releasing decremented it, and autoreleasing objects is a little more complicated. Again, the Cocoa Programming book explains it well. Garbage collection is an option, and if it's turned on, the retain, release and autorelease methods do nothing. However, if you are writing a library or framework to be used by others, you should program it as if garbage collection is turned off. That way applications can use it whether or not they have garbage collection turned on.

As for Web resources, http://cocoadevcentral.com/ is a great site with beginner tutorials. The CocoaDev Wiki at http://www.cocoadev.com/ contains detailed information on a lot of topics, and you can usually find some useful information and people on the cocoa-dev mailing list http://lists.apple.com/mailman/listinfo/cocoa-dev

iPhone development is a little different, and the details are restricted by an NDA. However, if you get approved by Apple to get access to the iPhone developer center, Apple has provided some great video overviews of the differences, which point you to the documentation you need to make the jump from Mac OS X to iPhone OS X programming.

I'd like to learn how to write application for Mac OS X.

Like how to use XCode properly, Cocoa syntaxes and examples, etc.

I'm already a web developer using ruby, php, mysql, rails, etc.

I looked through google quite some times but never found something palpable to learn from.

But I really want to make my own application, for fun and maybe business later.

Thanks a whole bunch for your tips!

You should start by learning Objective-C. Programming in Objective-C is an excellencent introduction to the language

If you're looking for a free resource this is an excellent web-site

Only after you have a solid understanding of the language would I worry about the different frameworks available.

Aaron Hillegass's book "Cocoa Programming for Mac OS X" is certainly up there. It would also be well worth your time to learn the C language well.

I am an experienced C++, C# programmer on Windows platform and would like to learn Objective-C to try out developing on the Mac and iPhone.

What books do you recommend me to start out with?

Thanks.

I'm reading Learn Objective-C on the Mac and find it good.

Cocoa Programming for Mac OS X by Aaron Hillegass is great for learning Mac programming.

To learn objective-c specifically -- not Cocoa or Cocoa touch -- I have and like:

Programming in Objective-C 2.0 (2nd Edition)

Programming in Objective-C 2.0 cover

The reason that I like this book is because it doesn't assume extensive knowledge of C. Of course, knowing C -- or any C like programming language will help. But this presents Objective-C as Objective-C the programming language and not Objective-C the extension to C. I think this is important because C and Objective-C have different ideology. Yes, they share attributes but programming in C is a different experience from programming in Objective-C. Your book should reflect that. :-)

Another question. I have been researching everything this wonderful community has offered me in terms of my journey to pursue game development.

I have come to the conclusion that I would prefer to develop on my native machine, OS X - eventually leading to the iPhone.

I already own both Big Nerd Ranch guide's, Iphone Programming - the Big Nerd Ranch Guide and Learn to Program on Mac OS X - the big Nerd Ranch Guide.

My goal that I am trying to shoot for is a game similar to Blizzard's Diablo II.

When going through these books, everything seemed a bit over my head due to lack of Objective-C experience (so I suspect).

What it the best beginner friendly way for me to reach my goals? I have been looking at Objective-C books for beginners from Apress and the like, or straight C books.

How would experienced developers such as yourself guide a newbie through this path?

Regards

  • edit -

To answer why I have picked the apple route, it just looks to be the most comfortable (environment is native to the machine). I may be very wrong though. I was looking at Unity, it supports C#, JavaScript and Boo. Others like Panda3D use Python. I am just not sure, it seems like the decision process has become rather challenging.

I find that a good way to learn a new language is to start with replicating common command-line tools like wc, grep, ls, etc. This will teach you the basics of I/O (both file and stdin/stdout) and some basic string parsing, as well as other goodies here and there. Additionally, you have a deterministic method of determining whether your program does it right or not, since you can easily compare to the standard command's output or behavior.

K&R, as well as Programming in Objective-C 2.0, are good places to learn the basics of C and Objective-C.

Once you have the basics of the language down, start with basic GUI programs (the ones in Hillegass's book are a good start). Once you can hook a basic GUI on the front of some underlying logic, it's time to start thinking more seriously about your game. Hillegass's book has a basic intro to using NSOpenGLView, which you can use to manually draw in 2D and 3D. It's important to note that when going through the examples in any book, you'll want to thoroughly understand what they're doing and how they're doing it, enough so that you can make some modifications yourself to enhance/change the behavior of the sample program you're working with.

Once you understand the basics of how your underlying game logic can hook to something the user can see, it's time to go find a game/drawing library that will get you where you're going. You definitely don't want to write all of the graphics routines yourself for a game similar to Diablo.

I'm a Windows (native, not .NET) programmer and I'd like to port an application to the Mac.

Actually, I believe it will be more of a rewrite, as the original depends on many activex controls.

As I have never used a Mac in my entire life, I'll need some guidance. O:-)

a) What book(s) would you recommend to make the move from Win32 to Mac OS?
b) Is there anything similar to Delphi (RAD) for the Mac?
c) Can anyone recommend (or not) Lispworks (www.lispworks.com)?
d) Is there anything similar to the Windows market of 3rd party COM components (so I don't have to write everything)?
e) Anything else I should be aware of the Mac market?
f) Oh, BTW, what Mac should I buy? O:-) (must be a laptop)

Thanks in advance

I've taught Cocoa programming to several Windows-experienced programmers. You may find a previous post on the subject useful.

Cocoa is a very different way of thinking then MFC and its kin. You will do much, much better if you take the time to learn how Cocoa approaches things and adapt to its mindset rather than trying to find the quickest way to implement your current way of thinking in ObjC. It is possible to write MFC-style code for Mac, but you will always be fighting the framework if you do. I've seen a lot of Windows developers struggle with this.

The best book to learn Cocoa is Cocoa Programming for Mac OS X. Assuming you are a C++ developer with a solid OOP background, this is the book to start with. If you have limited Object Oriented background, then start with Programming Objective-C 2.0.

You would be amazed how fast Objective-C can be to code once you understand the patterns. It really can be stunning compared to C++ in my experience. There are more RAD-like systems like REALbasic, and you can develop Cocoa apps in Ruby now which can be a bit quicker. But there really is no substitute in the Mac market for ObjC. It's hard to make an app that works like a Mac app without using the Mac frameworks, and Mac users tend to be much fussier about such things than Windows users.

I have no background in LispWorks, but LISP seems a terrible language for developing the kind of rich UIs that Mac apps are known for. I like LISP (quite a lot actually), but Functional Programming's "no side effects" philosophy seems at odds with most rich UI goals (especially as the Mac UI becomes more and more animation-centric). If anything, Mac programming is moving towards Declarative rather than Functional programming (Core Animation and Grand Central Dispatch have a lot of Declarative concepts creeping in).

There is not as large a third-party component market as there is for Windows. Some of this is because Cocoa already provides such a rich set of components, which MFC does not, and because well-behaved Mac apps are expected to use those components so that you work like all other Mac apps. There is definitely little market for commercial components in the vein of RadControls for .NET (very nice toolkit, that one). But there are quite a few nice free components out there with flexible licenses (generally MIT-based). A few of my favorites:

As I mentioned before, Mac users are picky about their UI. Much, much more so than Windows users. They expect things to be polished, and they expect things to integrate with all the little things that make Macs nice. That means drag-and-drop, Spotlight, services, Applescript, Expose, QuickLook, integrated spelling check, etc. etc. It's very hard to do all these things right if you don't use the built-in frameworks. That's why I recommend new Mac developers start at the beginning and learn the frameworks.

For a Mac, if you have a bunch of hardware lying around (like keyboards and monitors), then a Mac Mini is a nice cheap box. iMacs are great if you want an all-in-one, and any MacBook is appropriate if you like portability. There is no Mac on the market today that is not a perfectly fine development box. Obviously if you do a lot of work, an 8-core Mac Pro makes compiling much faster, but I've done a lot of professional development on a 13" MacBook. If you want to get in as cheaply as possible, look for refurbished or used (I love my refurbished Mac Mini). Any Intel-based Mac is going to be fine for development, at least while you're getting started.

I've been developing for quite a while but while I consider myself competent (or better) with C++, Java, C# & AS3/Flex in areas from web-servers to desktop applications to 3D games, I'm aware all these languages are pretty similar; even on the libraries side I know what to look for based on using libraries that do similar things in another language.

But Objective C I understand to be a different kettle of fish, and developing for mobile devices has always struck me as likely to be hard work since you have to develop on your PC and test on the actual device itself - my experience developing for PS2 put me off such things due to poor debuggers and other tools.

What's the reality? Is it a paradigm shift to move from web-servers and desktop apps and rich web-clients to iPhone... or for an experienced developer is it just another language to learn and new libraries to play with? Is there anything to be scared about at all?

edit: My main question on Obj-C specifically was if it's a different way of programming, like it would be moving to Haskell from Java for instance. It sounds this is not the case.

For starters, ObjC is fairly easy to grasp so long as you focus on the fundamentals. Don't worry about the syntax, there's not much there above C which I will presume you already are familiar with. There are excellent books out there this book is the definitive guide I recommend to most new users, Erica Sadun also has a good book on iPhone development, I recommend both of these highly.

Secondly, the tools aren't hard to use, and you will be pleasantly surprised with the debugger and other tool integration. Instruments was a long time coming, but it's indispensable for catching things like memory leaks, cpu time usage, and now power consumption.

But really, nothing to be scared about, and as for another platform to learn; well, yes and no. There is always going to be another thing to learn, regardless of iPhone or something else. Don't resist. :)

I'm a C++ and Javascript developer who is learning objective-c to be a hobbyist cocoa/objective-c programmer for mainly Mac OSX desktop applications. I'm pretty green when it comes to objective-c/cocoa, and I was wondering how I can add a button to my main view and bind a custom handler to that button when it's clicked? What's the best way to do this? I've done this many times with wxWidgets, but this is my first cocoa application to help me learn and get my feet wet.

I would also appreciate any book suggestions or learning resources that you could point me to.

Thanks!

Alex, I would highly recommend you check out some books before you dive into Objective-C. Coming from C++ and Javascript, you're going to have to better adapt your mindset to what you are going to learn, and if you don't prepare yourself, you're going to be very, very confused. As quixoto said, definitely take a look at Aaron Hillegass' Cocoa Programming for Mac OS X, as it will walk you through the process of creating applications and using Xcode and Interface Builder. Before that, however, I would highly recommend you check out Stephen Kochan's Programming in Objective-C 2.0, to get a primer on the language and its concepts (although C++ and Objective-C are supersets of C, they are both quite different).

I'm a web developer and I'm getting envious of all the cool iPhone apps. I know nothing about C or what ever language they use to make iPhone apps. I really have no idea where to start. What do I need to do? Should I take a class, buy a book? I have a pretty good grasp on programing, I do tons of HTML, CSS and Javascript development and some PHP and Action Scripting. I'm not very good with Object Oriented Programing but I think I could pick it up if I used it more. I love video tutorials like lynda.com or net.tutsplus.com. I learn best buy jumping in and getting my hands dirty.

You may start by some online videos as you love video tutorials, the Stanford course is one of the best.

Then you can pick up a book or two.

If you still feel comfortable after that, you may start a real project and ask questions on StackOverflow along the journey ;-)

Enjoy~

If you really want to know how to make a good iPhone app, don't take shortcuts. Leave all of the intermediate products out and forget about just wrapping a website up in a UIWebView. Learning how to do it the right way will make you a better, more well-rounded programmer.

Since you don't know much C or Objective-C, I'd recommend reading Programming in Objective-C 2.0 by Stephen Kochan. It's a great book for going from no C experience to learning Objective-C. It also includes some iPhone-specific stuff.

I'm new to Objective-C.

If I wrote this method declaration in .h

-(void)myMethod;

and this implementation in .m

-(void)myMethod{
    NSLog(@"This is myMethod");
}

How can I call it in my class' viewDidLoad method?

Thank you.

Assuming that you're calling myMethod on the same class as what implements viewDidLoad:

- (void)viewDidLoad {
    //...other code
    [self myMethod];
    //...other code
}

If you are having trouble with basic Objective-C though, I'd strongly suggest to either get a decent book on Objective-C, such as:

…or at least read a good beginners tutorial, such as:
http://www.cocoadevcentral.com/d/learn_objectivec/

There are quite a few more helpful beginners tutorials by Scott Stevenson here:
http://www.cocoadevcentral.com/

I'm soon going to be starting some iPhone Development (3.0) building a simple app that communicates with a web service and uses push notification.

My Objective-C is pretty much non-existent but I've already got some good information from this question and also from Apple's development centre.

Basically if you've developed with the iPhone before what caveats/hints/pitfalls/tips/etc could you recommened in general?

I agree, Cocoa Programming for Mac OS X by Aaron Hillegass is a great book to learn Cocoa, and it covers Obejctive-c nicely, but if you really want to KNOW the language, I would recommend: Programming in Objective-C 2.0: http://www.amazon.com/Programming-Objective-C-2-0-Developers-Library/dp/0321566157

Both are fantastic books and nicely complement eachother.

Its very important to remember that other people are having a hard time learning Cocoa too. Reading Aaron's book is a fantastic way to start. Reading source code is also another great way. THere is some open source iPhone projects (for example: wordpress), and there a bunch for OS X. Read what other people are doing so you can get the flow of an application. I found that to be the hardest part about learning (especially the Cocoa part).

I am a PHP developer, and want to learn objective-c usage withing its well known IDE - XCode to start building IOS apps for iphone and then sell them on AppStore. my questions are:

  1. What's the best (and easiest) documentation to start with ?

  2. Is it that easy for me (as a beginner objective-c developer) to attract customers on AppStore and get them to buy my IOS apps, or is there a huge competition among experts on AppStore so that there is no chance for beginners on AppStore?

  3. If there is any chance to sell my apps on AppStore, what's the possible profit for them on AppStore ?

thanks in advance.

What's the best (and easiest) documentation to start with?

I found this link (for PHP programmers): http://mohrt.blogspot.com/2008/10/objective-c-crash-course-for-php.html Otherwise go with books, and use xCode and read code.

Learn Objective - C: (Programming Objective C 2.0) - http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157/ref=sr_1_1?ie=UTF8&qid=1298891453&sr=8-1

Learn iOS coding: (Big Nerd Ranch) http://www.amazon.com/iPhone-Programming-Ranch-Guide-Guides/dp/0321706242/ref=sr_1_1?ie=UTF8&s=books&qid=1298891484&sr=1-1

Is it that easy for me (as a beginner objective-c developer) to attract customers on AppStore and get them to buy my IOS apps, or is there a huge competition among experts on AppStore so that there is no chance for beginners on AppStore?

If your idea is good and your app is well written sure. But there are a few competitors.

If there is any chance to sell my apps on AppStore, what's the possible profit for them on AppStore ?

There is no easy answer to your question here, but you will have a profit from apple with 70% of the product prize.

Good luck out there.

I come from a .Net C# background, what's the best way to learn how to program native applications for the iPhone?

Everyone has posted nice resources, but even if you already know the language you have to use, I just wanted to state it so that other people who probably don't know it, can see.

The language used for developing Apple sanctioned, native applications is Objective-C. Of course, you can mix in C and C++, but the SDK itself is in Objective-C, so you might want to learn that. It looks a bit scary at first to most people, usually those coming from higher level languages such as C#. The brackets and supposed 'verboseness' turns some people off. After a while though, it grows on you and you'll notice it's a very readable and self-documenting language.

I personally used the book titled Learning Objective-C which was perfect for me as someone who is already familiar with programming languages, preferably C-style languages, and wanted to learn about the main differences in that language. The other, longer and I imagine better reference of a book is the popular Programming in Objective-C 2.0. This book is longer and starts off assuming the reader has 0 programming experience, going over control structures, Object Oriented Programming basics, etc. I believe both books have cheaper and searchable PDF versions.

Have fun and I hope all goes well for you in this venture.

I've a great interest on iPhone Development and How i can start iPhone development ?

I've no basic deals with C but I've programming knowledge and concepts.

@property (nonatomic, readonly) BOOL isBlabla;

When speaking about properties I'm not sure what the official name for the keywords in brackets like (nonatomic, retain) is. I have referred to them as "property modifiers" and other names but that's probably not the correct term.

How should I call this group of keywords (nonatomic, atomic, readonly, readwrite, assign, retain, strong, etc.) that can be used in the @property brackets so that everyone knows what I'm referring to?

In the closest book to me presently, they are called "property attributes" http://www.amazon.com/Programming-Objective-C-2-0-2nd-Edition/dp/0321566157

A quick search of Apple's docs yields the same word: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html

And finally, the link to the specific section of the docs, which uses both "attributes" and your very own "keywords": https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW2

Possible Duplicate:
Getting Started With iPhone Development

hi

i am very new in Iphone application development . from where can i start the development . please provide some good tutorial and books

Thanks in advance

I'd recommend grabbing The iPhone Developer's Cookbook by Erica Sadun and Programming in Objective-C 2.0 by Stephen G. Kochan. There are many good internet resources too, such as:

You should also learn how to use Apple's iPhone Reference Library as it has all the information that all the sites above have, just presented in a different format. Once you learn to read the documentation, everything begins to get much easier.

Good luck and I hope that you are successful in your App Store adventures!

Possible Duplicate:
Developing for the Mac?

i dont know anything about mac os x developing .

if i want to start developing and learning in "mac os x" then what i have to do?

which software i have to download ?

which book i have to read ?

any good material for that ?

Here are two book recommendations:

1) About the language Objective-C which is used for OS X development: Programming in Objective-C 2.0

2) Great book about application programming on the Mac: Cocoa Programming For Mac OS X

I have decided to enter the iPhone App development arena and as such have a couple of questions:

  • Coming from a business management background and having no experience/knowledge whatsoever in developing, what would be the right way to start?

  • I am aware that I should learn Objective C, to begin with; as well as OOP etc... will reading books and fiddling with iPhone SDK put me on the right track?

What else do I need?

P.S: I am very aware that this will/might be daunting to begin with but I am prepared and motivated.

Here is what i did ( although i am from a programming background ).oder important

  • Intel based mac
  • Join dev program ( this could be the last step , but i wanted to something to keep my motivation high :) )

  • Read first 6 chapters of Programming in Objective-C 2.0

  • started watching stanford iphone course ( available on itunes )

  • Started reading the grape-fruit book ( while referring to 3 for obj c questions )

  • Review tutorials/projects from appsmuck

  • Figure out how to use apple documentation as reference

  • Subscribe to iphone blogs / podcasts like mobile orchard / iphone devs twitter accounts ( there are several good ones )

  • Add iphone cocoa xcode objective c tags to stackoverflow account

Update I was just reading this from prag programmers ..seems like high level overview that answers your question.

I'm looking for strategies and articles on making Carbon code 64-bit ready.

Carbon for 64-bit does not and will not exist. It's pretty much a dead end.

So in order to bring Carbon application and toolkits to 64-bit their GUI part will have to be re-written in Cocoa and Objective-C, right?

How can I minimize the effort I have to put into the transition? How can I minimize the amount of needed Objective-C code?

So in order to bring Carbon application and toolkits to 64-bit their GUI part will have to be re-written in Cocoa and Objective-C, right?

Yup.

How can I minimize the effort I have to put into the transition? How can I minimize the amount of needed Objective-C code?

  1. Learn Cocoa. Read The Objective-C Programming Language and the Cocoa Fundamentals Guide. Become familiar with MVC, KVC, and Objective-C. Bookmark the Foundation and AppKit framework references. Learn to love Interface Builder, for it is your friend (moreso in Cocoa than it ever was in Carbon).
  2. Get good at Cocoa. Read more Guides (if you're still on Leopard, use [1] instead). Write as many throwaway apps and even real apps as you can get away with in whatever time you have available. If you can, give them away under a BSD license, and write reusable source code and give that away, too. People will find bugs and some will tell you about them, and some will submit patches. Get to be able to write a complete app with a model layer, no more than two controllers, and at least one custom view or cell in a day.
  3. Read the Carbon Porting Guide, then port your app.

I came from Carbon myself. It's completely different—you may as well start fresh, ignoring your previous Carbon experience, and maybe you won't make some of the early mistakes I did (like skipping the model layer).

As for your app, you probably have a lot of surgery to do, as Carbon did not force you to keep UI and logic separate like Cocoa does. Cocoa enforces MVC; if you don't adhere to it, you pay the price by reinventing wheels and making and correcting mistakes.

That makes Cocoa sound like more work, but it's not. Porting is hard (inevitably), but otherwise, Cocoa is quite the opposite: Writing (and reading!) a Cocoa app is much easier than writing (and reading) a Carbon app. Once the porting is over, you'll be glad you switched.

Oh, and many people will recommend one or both of Cocoa Programming for Mac OS X by Aaron Hillegass and Programming in Objective-C 2.0 by Stephen Kochan. I have the first book, and have read some of it, but that was after I had already learned Cocoa, so I can't earnestly recommend it; that said, it is not bad, and I don't think you'd do wrong to read it. I have not even seen the second book, so I won't say anything about its quality.

[1]: file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/index-date0.html (Stack Overflow won't let me link file: URLs)

What the best books available right now on Mac and iPhone development ?

Thanks Michael

These two books were good:

The Apple online docs are actually pretty good too:

I'd stay away from this one, I didn't think it was very good:

Possible Duplicate:
Getting Started With iPhone Development

Any one Can suggest a book for begineer.I need all the basics

Thanks in advance

I read

Beginning iPhone Development by Mark/LaMarche/Nutting (47 Reviews, 4.5/5 stars)

and

iPhone SDK Development by Dudney/Adamson (31 Reviews, 4.5/5 stars)

and I can recommend both.

I recommend the "iPhone Programming" by Aaron Hillegass. ( Amazon Link - http://www.amazon.com/iPhone-Programming-Ranch-Guide-Guides/dp/0321706242/ref=pd_bxgy_b_img_c )

Aaron wrote the best cocoa programming book, also. ( If you are also interested in Cocoa programming, Aaron's Cocoa Programming is really good for you, too! )

Additionally, I recommend the "Programming in Objective-C 2.0" for learning objective-C ( Amazon Link - http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157/ref=pd_bxgy_b_img_b )

First of all a good Objective C book:

Then an iOS book:

I would start reading these two for the moment. They should get you up and running.

hey everyone i know this is sort of a rehash but i just need some advice. i know there are 100 different ways to approach programming and its pretty mind-numbing to think them all through, but my end goal is to be able to develop iphone applications at a level of competency to get an internship this summer (so by may / june 2011)

i know c++ very vaguely (so i guess i don't really know it after all) but i'm going into this with the mindset of a beginner because thats where i feel like i am.

would this be a solid approach to my goal? I know i need to learn concepts such as object-oriented design along the way and i'm hoping that these books take care of them:

1) Learn objective-c through: http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157/ref=cm_cr_pr_product_top

  • will this book teach me general programming concepts such as OO design? I know obj-C is the language to learn for iPhone dev but I also want to learn general concepts along the way

2) Probably dive into one of the Head First books concerning iphone development

My goal is to be able to build a game which showcases a level of competency to land a solid internship in a few months (the game would basically be my portfolio) and i just want to make sure this is a good step in the right direction. to be honest there's just so many ways to approach it that i can't quite figure out a good way of starting

any help or advice is greatly appreciated

thanks

Yes, that book will surely help you. After completing objective C. Refer this book for starting, building apps..

http://www.wrox.com/WileyCDA/WroxTitle/Professional-iPhone-and-iPad-Application-Development.productCd-0470878193,descCd-tableOfContents.html

I am seriously confused about the Objective-C #import.

I searched and found several tutorials saying that if I have lots of constraints like

#define val1 
#define val100

it's better to put all constraints in one file and import this file for reusing all values.

But i am still confused, I saw many code samples which #import all other files' headers in which there is is no

#define constraints 

These two files are normal UIViewControllers, but their headers are imported.

#import viewcontroler1.h 
#import viewcontroler2.h 
  1. When can we simply create objects of classes why import them?
  2. Where to import files in .h or .m?
  3. What to import, the .h or the .m file in Objective-C?

I am seriously confused, please help me.

I have both Stephen Kochan's Programming in Objective C published in 2003 and Programming in Objective-C 2.0 (2nd Edition) published in 2009. Both are excellent books, and I am refreshing my Obj C skills.

In both editions, there is a listing for the Fraction with Classes program. It is listing 3.4 in the first edition, listing 3.2 in the second edition.

Here is listing 3.4 from the first edition:

#import <stdio.h>
#import <objc/Object.h>
///Interface section
@interface Fraction: Object
{
    int numerator;
    int denominator;
}

-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(id)init;

@end

//Implementation section

@implementation Fraction;
-(void) print
{
    printf(" %i/%i", numerator, denominator);
}

-(void) setNumerator:(int)n
{
    numerator=n;
}

-(void) setDenominator:(int)d
{
    denominator=d;
}

-(int) numerator {
    return numerator;
}

-(int) denominator {
    return denominator;
}

@end   //Implementation

// Program section
int main (int argc, const char * argv[])
{
    Fraction *myFraction;

    myFraction=[Fraction alloc];
    myFraction=[Fraction init];

    [myFraction setNumerator:1];
    [myFraction setDenominator:3];

    printf("The value is:");
    [myFraction print];
    printf("\n");

    [myFraction free];

    return 0;
}

The second edition became much more Apple/OS X centric. Instead of focusing on GCC, the text is more focused on xcode. Instead of the generic objc/Object.h import, the listing were translated to use the OS X Foundation class framework.

Here is listing 3.4 from the second edition:

// program to work with fractions - class version  

#import <Foundation/Foundation.h>  

//---- @interface section ----  

@interface Fraction: NSObject  
{  
    int numerator;  
    int denominator;  
}  

-(void) print;  
-(void) setNumerator: (int) n;  
-(void) setDenominator: (int) d;  

@end  

//----@implementation section ----  

@implementation Fraction  
-(void) print  
{  
    NSLog (@"%i/%i", numerator, denominator);  
}  

-(void) setNumerator: (int) n  
{  
    numerator = n;  
}  

-(void) setDenominator: (int) d  
{  
    denominator = d;  
}  

@end  

//---- program section ----  

int main (int argc, char *argv[])  
{  
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  

    Fraction *myFraction;  

    // Create an instance of a fraction  

    myFraction = [Fraction alloc];  
    myFraction = [myFraction init];  

    // Set fraction to 1/3  

    [myFraction setNumerator: 1];  
    [myFraction setDenominator: 3];  

    // Display the fraction using print method  

    NSLog (@"The value of myFraction is:");  
    [myFraction print];  
    [myFraction release];  

    [pool drain];  
    return 0;  
}   

Of course the older version does not compile on the newer XCODE, and I do not find that terribly surprising. However, the older edition code no longer runs if compiled on recent versions of GCC on Linux or Windows.

The specific run-time error is init method not found but the Kochan book states that the init method need not be defined on a class derived from Object. Indeed you do not need to define -init -alloc or free on NSObject but gcc 4.2.1 warns that they are not defined for Object. I am assuming that this code could be successfully compiled and executed when Kochan put out his first book. The Foundation classes and NSObject, I believe, are Apple only.

I can compile and run 30 year-old C code, but 7 year old Objective C is not longer useable? Has Objective C, essentially, become an Apple only language with no real support outside of Apple only compilers and technologies? That is the question.

I have just started to learn Objective - C. I have done one year of Java programming and one year of Actionscript. I need to find a website or blog which tells me how to do the basic things for example declare a variable or how to write a method and function. I cant seem to find this anywhere. If someone could give me some good links that would be great. Thanks

I would highly recommend the book Programming in Objective-C 2.0 by Stephen Kochan.

I used the older version when I was learning Objective-C and still reference it on occasion. It is an excellent introduction to the basics of the language.

Im trying to write some code where the computer creates a random integer between 1 and 12 and I want to be able to compare that number elsewhere in my code. How do I call that number in a method? Im very new to this so any help is appreciated

heres how i called it in the .h

int losingVault

in the .m this how i create the random number

losingVault=rand()%12+2;

how do i call that elsewhere in my code?

Well, this isn't a lot to go on. It seems like you may need some basic help understanding Objective-C. There are a couple books people like to recommend, Programming in Objective-C by Stephen Kochan is probably the most popular.

So, the way your example code is written, losingVault will probably have visibility in the entire class in which it was defined. If you look in your .h file, int losingVault; is probably within an @interface {ClassName} block. In your .m file, there should be a matching @implementation {ClassName} block. Anywhere inside that block should be able to access the variable by just calling losingVault. You could make that variable visible outside of that class in a number of ways.

I hope this helps.

So, I'm learning Objective C by this book. It is thought to be great and all. http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157/ref=sr_1_1?ie=UTF8&qid=1303332025&sr=8-1

But after installing new Xcode (version 4) when i tried to finish the exercise form the book (3.2) it gives me like 10 compilation errors that I can't identify. What can I do about this? Getting xcode 3 is not really an option. For example there are many semantic errors that keep saying undeclared identifiers pointing to empty spaces...

also it isn't accepting this line of code:

Fraction *myFraction;

I got class myFraction, what's wrong with this one?

Also there is method declaration in this class

- (void) setNum : (int) n;

it says, expecting member name or ; after declaration specifiers. What can this mean? There already is a semicolon there.

Fraction *myFraction;

I got class myFraction, what's wrong with this one?

In this statement, Fraction is the name of your class... myFraction is the name of your object. If your class is really called myFraction, this statement would be:

myFraction *myFraction;

Also there is method declaration in this class

- (void) setNum : (int) n;

it says, expecting member name or ; after declaration specifiers. What can this mean? There already is a semicolon there.

I don't see anything wrong with this... can you post the code that surrounds this method declaration?

well i have search a lot for iphone material to get started ,

but i found most of the stuff that divided either in iphone development or in learning objective C only.

Can someone please send me links/ebooks/articles/videos where once can learn objective c and iphone together ?

It is arguably better if you learn objective-c before delving into the iphone framework (Cocoa Touch and associated frameworks). The iphone sdk is built around objective-c and a firm understanding of the language is absolutely essential for understanding the documentation about how to use the iphone sdk.

Having said that, an excellent book that teaches objective-c and then provides an introductiojn to iphone programming is Kochan's Programming in Objecitve-C This will get you up and running with objective-c in a minimal amount of time, after which you can start with Beginning iPhone 3 Development for a thorough coverage of the main iphone sdk paradigms.

Yes I've seen questions like these before but they're all for people who basically want to start from scratch. I come from AppleScript Studio (for those who do not know it, it's AppleScript in Xcode with IB etc.). The only things new to me are related to interface and implementation files. In my code I've already written 2000+ lines of ObjC, so it's not the syntax. But I fail to understand inheritance, accessing variables from other class files, etc.. The way I use ObjC is having one NSObject in IB which its class is changed to something new by me and then all my code is written in that one implementation file. My biggest problem is finding out how to access parameters from other classes.

So do any of you have any tips on where to start? Normally I'd start from scratch with a book but I seem to fairly be able to write code as long as it's located in one big file...

Thanks for your help.

Although you understand Interface Builder, it's very clear that you don't understand Objective-C or Cocoa very well at all. You need to stop flailing around and give yourself a firm grounding in the language and frameworks. The only way to do this properly is to start at the beginning.

You should start by learning Objective-C properly. In my opinion, the best way to to this is to read Stephen Kochan's superb Programming in Objective-C 2.0. This will teach you how to write Objective-C properly and explain object-oriented coding, class inheritance and so on. You should read the book cover to cover and do all the exercises.

You should then read Aaron Hillegass' Cocoa Programming for Mac OS X which will teach you how to take Objective-C and marry it to Interface Builder and the Cocoa frameworks to produce working Cocoa apps.

You should also read Cocoa Design Patterns which will explain what the design patterns in Cocoa are and how to use them to your advantage to write Cocoa apps the right way.

Possible Duplicate:
Great UIKit/Objective-C code snippets

what are the best code snippet sites for iphone / objective c

Read Programming in Objective-C by Stephen G. Kochan.
Btw, a good link here. Go through it : A Code Library for iPhone Objective-C Applications

Possible Duplicate:
Best way to learn Objective-C

Hi all..

I'm very new to iphone..

I want to learn basics of objective-c .please give some links for related studies..

and giv some sample applications for begin.

Thank you

I fully recommend viewing this site, as I have heard many good things of it:

http://cocoadevcentral.com/d/learn_objectivec/

If you're more the pick it up and read kind of person, might I suggest the following book:

http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157/ref=sr_1_1?ie=UTF8&qid=1305617578&sr=8-1

Third edition will be out next month, so you may want to wait on it.

I just began iOS development, and find it relatively hard to comprehend. I have browsed through a lot of tutorials, and the Apple documentation too, but what i really need is tutorials that help- in understanding the basics before tackling actual problems. Any references anybody could point out would be highly appreciated. YouTube videos are also welcome. Thanks

Tack a look at video tutorial of Lynda. Its good to take a look at that video and than start developing app in iPhone.

For good tutorial my favorite sites are Raywenderlich, EDUMobile, mobileTutPlus, Technotopia.

And for sample code i suggest GITHub, Cocoacontrols, Code4app.

And this is really helpful books, Programming in Objective-C 2.0 (2nd Edition), Beginning iPhone Development: Exploring the iPhone SDK,

I am new to iphone .How can i develop appstore using store kit .can any one explain the necessary steps ..Thanks in advance

1) You need a mac. If your on a budget get a macbook or mac mini.

2) Get the developer tools with the iphone SDK. This will give you GCC and all of the basic tools required. Its free but you do have to register at developer.apple.com . You can pay the $99 later on when you actually are ready to sell an app in the app store.

3) You need to know objective C. If have C experience you can pick up objective C pretty fast. I recommend "Programming in Objective-C" by Kochan

4) Learn Cocoa. The book that really opened my eyes to this was "Cocoa Programming for Mac OSX" by Aaron Hillegass. Any of the Aaron Hillegass books are great. I think he has some specific stuff to the iphone now as well.

5) Learn Cocoa Touch. I would use the online documentation. Its gotten me pretty far.

At this point your off to a good start. I highly recommend reading the apple documentation and using google. If you like to learn by looking at working code, Apple also has allot of ready made simple apps. There is allot of information out there for people willing to look it up. Don't be afraid to ask questions here but be specific and provide lots of details. No one started out knowing everything. I wish you happy learning and good luck.