• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Properties and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Properties and bindings


  • Subject: Re: Properties and bindings
  • From: Roland King <email@hidden>
  • Date: Wed, 24 Sep 2008 10:49:01 +0800

you mean you want it to be read-only for other users, but you want the object to be able to set it itself without jumping through hoops?

There's something about this in the properties description in the objective-c documents.

What I've been doing for this (ie having semi-private properties and methods) is the following

in the .h file you declare your public interface

@interface MyObject
{
@property(readonly) NSInteger myInt;
}

.. but then in the implementation file, the .m, I add a category to the class which has all my private stuff in it, so the top of my .m file looks like this

@interface MyObject ()
{
@property( readwrite) NSInteger myInt;
// .. and I put other 'private' methods in there too
}


then people who just import your .h file will get a compiler error if they try to use myObjInstance.myInt = 123 because it's declared R/O for them, but in your implementation file it's been redeclared read- write and you can use it.


Note that this REALLY DOES synthesize a setMyInt() method and it's not really private, it's just a bit hidden. So it can be called by other code if it wants to call it and doesn't care about the 'object may not respond to selector' errors.


On Sep 23, 2008, at 11:44 AM, 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?

_______________________________________________

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

_______________________________________________

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


References: 
 >Properties and bindings (From: "D.K. Johnston" <email@hidden>)
 >Re: Properties and bindings (From: Jason Coco <email@hidden>)
 >Re: Properties and bindings (From: "D.K. Johnston" <email@hidden>)

  • Prev by Date: Re: Properties and bindings
  • Next by Date: Re: Properties and bindings
  • Previous by thread: Re: Properties and bindings
  • Next by thread: Re: Properties and bindings
  • Index(es):
    • Date
    • Thread