Re: Syntax question
Re: Syntax question
- Subject: Re: Syntax question
- From: Ondra Cada <email@hidden>
- Date: Sat, 25 May 2002 12:33:34 +0200
On Saturday, May 25, 2002, at 09:10 , Hisaoki Nishida wrote:
Would this code work as expected?
Very probably not.
[tileInfoList objectAtIndex:tileNum]->rcSrc->origin->x = tRect.origin.x;
tileInfoList is a NSMutableArray.
tileNum is an int.
rcSrc is NSRect.
Therefore, there are no pointers inside, and you want '.' instead of '->'.
tRect is also NSRect.
You can assume that the object pointed to by tileNum is a struct
containing rcSrc.
You can't. An object is not a struct, nor vice versa.
You can achieve the desired result by using @public in the object
interface, and proper cast, but it is THE BAD WAY of doing things, since
it violates encapsulation. IMHO, it would be better to use NSValue-encoded
rects than that.
But I'm not sure if it will be recognized as a struct, and instead an id?
If so, what should I do?
Cleanest: use an object which contains the NSRect, and make the
appropriate accessors for something like
[[tileInfoList objectAtIndex:tileNum] setRcSrcX: tRect.origin.x];
or worse
[[tileInfoList objectAtIndex:tileNum] rcSrc].origin.x=tRect.origin.x;
[tileInfoList objectAtIndex:tileNum] returns the struct by reference
Actually, it can't contain structs at all -- [anArray addObject:anNsRect]
would crash (since array would try to retain it).
(?) so I thought that '->' would work here. Unless I have to typecast the
struct or something?
Encapsulate it. Since I don't know your application, I can't say for sure,
but there is a non-trivial probability you could and should re-factor it
so that this problem disappears (like, you store rects in array to
construct some views, whilst you should store directly those views, or
alike).
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.