• 0

Learning Objective-C


Question

Hey guys,

I am just about to start learning iPhone application development and not sure exactly where to start, I already have knowledge of C# and Java but I want to get into the whole developing applications for iOS and was looking for some recommendations on where to began based on that I already have knowledge of Java and C# which both have the similarities.

From what I can see Objective-C is not much different either, the only things I don't understand much are Pointers, the whole " * " thing, I have never come across anything similar in Java or C# to know what those are for or even do. Can anyone recommend me where I should start? Eventually I would like to get into the whole OpenGL iPhone games application development and build a basic game.

Can anyone also link me to a good Objective-C for dummies and any additional books for iPhone application development and any good places for cheat sheets like this http://www.dummies.com/how-to/content/objectivec-for-dummies-cheat-sheet.html as I can see what is different from C#/Java in Objective-C

Thanks!

Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 0

C# has pointers... ???

If they do I have never ever had to use them the only type of "Pointers" I know is when enumerating over something and the "Pointer" is the current location at where its at.... is it the same in Objective-C??

Link to comment
Share on other sites

  • 0

Pointers are just variables that point a memory address space where a value (variable) is held.

Read this, http://www.cplusplus...orial/pointers/, or read my horrible explanation.

When you make a new variable such as

int a = 10;

a spot in memory is allocated for that variable. This memory location has an address. Lets say our memory address for int a is 5.

You then can create a pointer and assign it the value of the memory location of a.

int * b = &a;

b is an integer pointer with a value of 5, which is the memory address of a. The ampersand is the reference operator, it'll give you the memory address of a.

int c = *b;

The asterisk is the deference operator. This will set the integer c to the value which is pointed to by the pointer b. b has been set to 5 which is the memory address of a. So this will set c to the value of a, which is 10.

Link to comment
Share on other sites

  • 0

C# does have pointers. You don't have to use them but they are there.

Maybe first try from Mono. There is MonoTouch for iOS http://xamarin.com/monotouch. Thanks to this you could still use your C# knowledge.

Montouch is a bit pricey though, I am not exactly a company or business trying to use skills I already have just to quickly deploy an iPhone app, which I believe myself is what things like Monotouch, Phonegap etc all target at. I want to learn how to write them natively using Xcode and also gain my knowledge of Objective-C. I just did some searching on Google about Pointers in C# and it says they are generally never needed or used in C# which may be why I have never come across them, neither have I seen anyone use them when writing C#. It's just I seem to see them used a lot more in Objective-C why is this?

Link to comment
Share on other sites

  • 0

It's just I seem to see them used a lot more in Objective-C why is this?

1) Pointers are fast so if you really want to get the most juice from your app you will need them. But it's really easy to get memory leak with bigger programs.

2) Objective-C just like C/C++ didn't had garbage collector before. Right now they do have some type of automatic memory handling solution but last time I checked (around 2 years ago) it was not available in iPhone.

While it's nice that you want to learn Objective-C, it's a language used only on Apple platform. Mono is available for every mayor platform (Linux/Windows/Mac/Android/iOS).

Unity3D uses Mono.

Objective-C have really ugly syntax.

Additionally, learning OpenGL is not a one day task. So if you add it together you are facing quite a long learning journey.

As for MonoTouch price, if you pay you will have bigger motivation :). If you fail you will know for sure that you really didn't wanted to learn iOS development.

Link to comment
Share on other sites

  • 0

And "Xamarin trial software does not expire, but enables development and testing against the iOS Simulator and/or Android emulator only." so you can try Mono as long as it will take you to learn it.

Link to comment
Share on other sites

  • 0

1) Pointers are fast so if you really want to get the most juice from your app you will need them. But it's really easy to get memory leak with bigger programs.

2) Objective-C just like C/C++ didn't had garbage collector before. Right now they do have some type of automatic memory handling solution but last time I checked (around 2 years ago) it was not available in iPhone.

Objective-C have really ugly syntax.

Not sure what you are talking about but pointers are the foundation of Objective C. It's how you address objects stored in memory. You cannot not use pointers. Everything in Objective-C is an object and thus aside from integers, floats and chars you need to use them.

Memory management was a pain before but with iOS 5 we got the ARC. Automatic Reference Counting. So after this we don't have to do anything anymore to keep track of our objects in memory, pools and have to worry when to release an object.

Also, once you learn Objective-C syntax, how it works, what synthesize, properties, interfaces are, how methods are constructed (the only thing that's really very very different - and in some ways much better than other languages) it's not really that difficult at all.

Objective-C is very verbose. Method calls are made in a verbose way so you know exactly what parameter you need to put while unlike with Java and other languages you just call it like this myClass.method("someparam", "anotherparm") where you don't have a clue what those 2 things are.

I was fighting Obj-C for a loooong time because I felt so comfy within ECMAScript based languages and Java that I just hated it.. But then I approached it with an open mind and started to appreciate it more.

Link to comment
Share on other sites

  • 0

Superkid.. Objective C is different. Java and C# won't help you much and you have to throw it away. However, you don't throw away basic OO principles. They apply the same way in Objective C as they do in other languages, maybe more so than ever.

One big difference in approach is that Objective-C/iOS SDK/Xcode use delegates. You can observe those as basically events you can define in your class as methods that some other object will assume you have thus creating a very great way for objects to react to something happening in a completely different object/class. This is visibile with ViewControllers when you do iOS dev.

What I would recommend to from the heart is to watch courses by Simon Allardice on Lynda.com. The man is an amazing teacher.

Watch Foundations of Objective-C first (he has it updated with both manual memory management - the old way, and he updated it recently with ARC).

When you finish that, watch his iOS SDK 5 course where he guides you through the basics of working with Xcode/Interface builders, shows you everything you learned from Foundations course and how it applies to the iOS SDK.

That will be a good start for you.

Link to comment
Share on other sites

  • 0

If there is one book i could not recommend enough its the Big Nerd Ranch Guide: http://www.bignerdranch.com/book/ios_programming_the_big_nerd_ranch_guide_nd_edition_

I know loads of people who have successfully learnt with the help of this book, from non programmers to web devs etc.

Also check out the stamford courses on itunes. Know these are highly rated.

Link to comment
Share on other sites

  • 0

First thing, Objective-C is NOT C#. Im getting the impression people are getting the 2 mixed.

Second, C# does indeed support pointers but it isnt used too much. For basic desktop applications, pointers should not be used.

Third, if you can program in C# for iOS do it; Way better than Objective-C.....

Link to comment
Share on other sites

  • 0

Not sure what you are talking about but pointers are the foundation of Objective C. It's how you address objects stored in memory. You cannot not use pointers. Everything in Objective-C is an object and thus aside from integers, floats and chars you need to use them.

Since Objective-C didn't had GarbageCollector before it had to be build around pointers. C# was build from ground up around GB and that's why it doesn't need them. That's why you see more pointers in Objective-C than in C#.

Link to comment
Share on other sites

  • 0

One big difference in approach is that Objective-C/iOS SDK/Xcode use delegates. You can observe those as basically events you can define in your class as methods that some other object will assume you have thus creating a very great way for objects to react to something happening in a completely different object/class. This is visibile with ViewControllers when you do iOS dev.

Delegates feature heavily in C# too, especially if you hook up custom events ;)

Link to comment
Share on other sites

  • 0

First thing, Objective-C is NOT C#. Im getting the impression people are getting the 2 mixed.

Second, C# does indeed support pointers but it isnt used too much. For basic desktop applications, pointers should not be used.

Third, if you can program in C# for iOS do it; Way better than Objective-C.....

Your third point is pretty bad advice. The programming language is only a small part of development on any given platform. The frameworks are what help you do the heavy lifting. And for iOS, the best framework is Cocoa Touch. Therefore Objective-C is the best tool for the job. Don't make the mistake of seeing nails everywhere if the tool that you're most familiar with is the hammer.

Link to comment
Share on other sites

  • 0

As for the OP's question, I too highly recommend Objective-C Programming, the Big Nerd Ranch Guide. Again, I also recommend the Stanford course, available through iTunes U.

And like others have mentioned, if you want to build a game, you can leverage your knowledge of C# if you use the Unity game engine. You can write scripts for Unity in either C# or JavaScript.

Objective-C is verbose because of its use of named arguments. It might feel strange at first but you get used to that very quickly. Xode's Autocompletion helps. You'll then find that you don't need to document method parameters in comments anymore since your code is self-documenting in that respect. So this also has an upside. Follow the conventions and the design patterns and you'll find that you don't tend to write many comments when writing with Cocoa Touch. Cocoa Touch is a very nice framework. Learning Objective-C is worth the price of entry IMO.

Objective-C itself is getting more beginner friendly every year. You don't need to do manual retain and release (memory management uses reference counting) anymore - just use ARC. And they have finally added literals for NSNumber, NSArray and NSDictionary. They have also added automatic property synthesis. Syntactically things have improved. However, because the language has been evolving, you really want to get material that is up to date if you're just starting to learn Objective-C.

Good luck :)

Link to comment
Share on other sites

  • 0

Thanks for all the advice guys! I can see that in some areas of objective-c it still has its similarities to other languages like Java and C# which in a way does make it easier for me. The first thing i notice different is that the main void has to return a number? unlike C# its just a generic method. I believe returning 0 means success?

I am not going to be using MonoTouch and want to learn Objective-C for real because I am not someone who needs to get an app out quickly which like Mono, Phonegap etc target and I am someone just wanting to learn as a hobby. Hopefully I can come back here in a years time and say I have mastered all the main parts of programming in Objective-C but will see.

Thanks again :D Lots of good advice!!

Link to comment
Share on other sites

This topic is now closed to further replies.