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 Apr 7, 2011, 09:13 PM   #1
teguh123
macrumors member
 
Join Date: Mar 2011
In Init, does self refer to the class or the instance?

Also is there any case where we call alloc and not init after that?

What confuses me is things like

self= [super init]

Basically, if self is a pointer to the class, we're tell self to point to the address described by [super init]

The problem with that is self should already point to whatever address returned by alloc right?

So why change it?
__________________
How to Learn Math
teguh123 is offline   0 Reply With Quote
Old Apr 8, 2011, 01:09 PM   #2
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
In any instance method (-), self refers to the instance. In any class method (+), self refers to the class. Always call an init method after calling +alloc. The reason to set it is that some classes play tricks in -init and don't return the same object that +alloc did.
Catfish_Man is offline   0 Reply With Quote
Old Apr 8, 2011, 01:28 PM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
Cocoa Fundamentals Guide

In particular, read the sub-section on "Basic Subclass Design". Ideally, you should read the entire guide.
chown33 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

Similar Threads
thread Thread Starter Forum Replies Last Post
WHERE TO INIT a CLASS joak iPhone/iPad Programming 8 Mar 20, 2014 10:23 AM
Assigning new instance of a class to an object that had an instance of the class moonman239 iPhone/iPad Programming 3 Oct 11, 2013 12:58 PM
Class Method -> Function -> Instance Method? Blakeasd Mac Programming 11 Jun 19, 2013 02:53 AM
How to have user create class instance Abrexas iPhone/iPad Programming 21 Mar 28, 2013 12:54 PM
Help With Bug: -[NSConcreteValue class]: message sent to deallocated instance ArtOfWarfare Mac Programming 5 Jul 11, 2012 11:13 PM

Forum Jump

All times are GMT -5. The time now is 10:34 AM.

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

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