Re: [Learning Cocoa Qs] View Hierarchy & Pointers to Cocoa data structures
Re: [Learning Cocoa Qs] View Hierarchy & Pointers to Cocoa data structures
- Subject: Re: [Learning Cocoa Qs] View Hierarchy & Pointers to Cocoa data structures
- From: Finlay Dobbie <email@hidden>
- Date: Sun, 8 Jul 2001 14:05:46 +0100
On Sunday, July 8, 2001, at 01:37 pm, Dale Gillard wrote:
QUESTION 2
OK. My second question relates to the Dot View project on pages 133 -
138. Page 135 contains example 8-1. It's code declaring a header file
for DotView, including these 2 variables:
NSPoint center;
NSColor *color;
My question is: why is one a variable, and the other a pointer to a
variable? Is this because the NSPoint class always returns an object of
NSPoint when it's created? And that the NSColor class returns a pointer
to a NSColour object when it is instantiated?
I've had a look in the Cocoa Help but can't find any info for NSPoint
(Objective C version). (There is a Java version of the help info in
Cocoa Help.) I've also had a look for and found the NSColor Cocoa Help
info. But I can't find where is says what is returned when an object of
this type is instantiated. That is, whether it's a pointer or a
variable.
Am I missing something in the help documentation? Am I missingn
something in my knowledge of C (I've done some C++ at university). If
not, how do others know whether to declare a variable or a pointer to a
variable?
NSPoint is a C structure, NSColor is an object.
NSPoint is defined as:
typedef struct _NSPoint {
float x;
float y;
} NSPoint;
See here:
file:///Developer/Documentation/Cocoa/Reference/Foundation/ObjC_classic/TypesAndConstants/
FoundationTypesConstants.html
You can allocate an NSPoint dynamically, should you wish, by using
something similar to:
NSPoint *center = malloc(sizeof(NSPoint));
Objects are always allocated dynamically.
In java, there is no such thing as a C structure, so I guess NSPoint is
probably a class (I'm not sure though).
I'm pretty sure all of that is correct, and hope it helps,
-- Finlay