开发者

Synthesizing an accessor for a member of a struct

Let's say my object has a CGRect property named rect.

I want to maintain a single CGRect rather than individual CGSize开发者_如何学编程 and CGPoint (for comparison against other CGRects with CGRectContainsRect()) but I want accessors for the individual members so I don't have to recreate a whole new CGRect every time I want to change one or the other.

I thought I'd try:

@synthesize size = rect.size;
@synthesize position = rect.origin;

But the compiler didn't like that. Is there a way to do this without writing custom getter/setters?


Nope. The @synthesize directive can only take the names of instance variables, not arbitrary expressions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜