Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 5, 2011, 03:20 PM   #1
jwei92
macrumors newbie
 
Join Date: Jun 2011
Returning a pointer

I've looked through a couple threads and am still lost on returning pointers.

I am currently in the process of learning Obj-C with not previous programming background.

I know some basics, but the only thing I cannot seem to grasp is in Kochan's Objective-C 2.0's book (Chapter 8 - A Point Class and Memory Allocation)

I know how to allocate, but here are the parts that confuse me:

Code:
@interface Rectangle:NSObject 
{
    int width, height;
    XYPoint *origin;
}

-(XYPoint*)origin;
-(void)setOrigin:(XYPoint*)pt;
I do not understand why the method returns pointers and such. Sorry if my question isn't clear, but can someone elaborate on why you return a pointer and not just an integer?
jwei92 is offline   0 Reply With Quote
Old Jun 5, 2011, 03:29 PM   #2
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Dallas, TX
All objects are gotten to in Objective-C via a pointer. That's it. Passing an object? You pass a pointer. Getting one back? Pointer. End of story. If it's just an int, sure... just return the int. There may be some reason to return a pointer to a primitive (maybe you want to modify it and have that affect something else that also uses the value in that memory location), but with objects there is no question.

-Lee
lee1210 is offline   0 Reply With Quote
Old Jun 5, 2011, 03:38 PM   #3
larswik
macrumors 65816
 
Join Date: Sep 2006
That was the point I got to in that same book. When he started in with pointers and self it got complicated. I then put that book down and Thought, Objective C is built on top of C. So I got the book "Learn C on the Mac" http://www.amazon.com/Learn-C-Mac-Da.../dp/1430218096 and that book was pretty easy to follow, this was end of last year.

I have now started back on learning Objective C and from the C book I understand all of the pointer concepts, data structures , functions and so on. Since I liked the Aprees book Learn C on the Mac I decided to start with Learn Objective C for Absolute Beginners by the same company. I just started reading it the other day.

If it gets hard for you, like me, then I recommend taking it a step back to something simpler. This is from experience.

-Lars
larswik is offline   1 Reply With Quote
Old Jun 6, 2011, 10:23 AM   #4
Shawnpk
macrumors 6502
 
Join Date: Jan 2011
Location: Los Angeles, CA
Quote:
Originally Posted by larswik View Post
That was the point I got to in that same book. When he started in with pointers and self it got complicated. I then put that book down and Thought, Objective C is built on top of C. So I got the book "Learn C on the Mac" http://www.amazon.com/Learn-C-Mac-Da.../dp/1430218096 and that book was pretty easy to follow, this was end of last year.

I have now started back on learning Objective C and from the C book I understand all of the pointer concepts, data structures , functions and so on. Since I liked the Aprees book Learn C on the Mac I decided to start with Learn Objective C for Absolute Beginners by the same company. I just started reading it the other day.

If it gets hard for you, like me, then I recommend taking it a step back to something simpler. This is from experience.

-Lars
+1 These are the books I started with. They are much easier to digest than Kochan's book. Kochan's book is a great 3rd book to read.
__________________
My iOS Apps: Schedules, Pitch Fever, Gridiron Fan
Shawnpk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Was going to return iPad because of factory problem but it fell and got dented gabriellanata iPad 23 Jan 26, 2014 05:59 AM
Returned 13" MBA, kept 15" MBP ckeck MacBook Air 16 Aug 1, 2011 04:52 PM
Returning for backlight bleeding robbyneal iPad 6 Mar 28, 2011 02:41 AM
Return policy amnesty on 34 day old MBP? CAWjr MacBook Pro 4 Feb 25, 2011 09:41 AM
Return my new Macbook Pro 15, or not? Politis MacBook Pro 23 Jan 7, 2011 03:08 PM


All times are GMT -5. The time now is 07:55 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC