Re: Properties and bindings
Re: Properties and bindings
- Subject: Re: Properties and bindings
- From: Andrew Merenbach <email@hidden>
- Date: Tue, 23 Sep 2008 19:55:00 -0700
On Sep 22, 2008, at 8:44 PM, D.K. Johnston wrote:
Thanks for the explanations: it does make some kind of sense now.
The reason I was looking at both forms is that I want the myInt
property to be read-only, but I want the MyObject instance to be
able to set it. If I do this:
@property(readonly) NSInteger myInt;
I can't do this in MyObject:
self.myInt = 123;
without generating a compiler error. And as you've all explained, I
can't do this either:
myInt = 123;
because the textfield value won't be changed. Is Jason's suggestion
the best way to get around this problem?
Hi!
Check out this link -- <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_5_section_4.html
>. It examines what I believe to be similar to your issue.
Basically, you can declare a property as readonly in the interface,
but use either a subclass (shown on the page) or a class extension
(new in Objective-C 2.0, but that shouldn't be a problem, since
properties are, too) to override it in your implementation.
For example, leave it declared as readonly in your interface:
@interface MyClass : MySuperclass {
NSInteger myInt;
}
@property (assign, readonly) NSInteger myInt;
@end
... then do this in your *implementation* file:
// this is your class extension
@interface MyClass ()
@property (assign, readwrite) NSInteger myInt;
@end
@implemtnation MyClass
// normal class stuff
@end
This would then have the effect of making a property readonly to all
external classes, but readwrite to itself.
Cheers,
Andrew
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden