开发者

Synthesizing an accessor for a member of a struct

开发者 https://www.devze.com 2022-12-15 05:29 出处:网络
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 CGRect

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

精彩评论

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