Graphics Programs Reference
In-Depth Information
This is because instance variables of a class are protected from access by other objects.
There are three visibility types for instance variables: protected (the default), private , and
public . A protected instance variable can be accessed within the methods of the class it
was declared in and all the methods of any subclasses. However, if a method from another
class wants to access a protected instance variable, it must use an accessor method.
A private instance variable, on the other hand, can only be accessed within methods for
the class it was declared in - not the methods of other classes or even methods of a sub-
class. A public instance variable can be accessed anywhere using the arrow notation. The
syntax for declaring the visibility of instance variables looks like this:
@interface MyClass : NSObject
{
@public
NSObject *publicVariable;
@private
NSObject *privateVariable;
@protected
NSObject *protectedVariable;
}
In other languages, it is sometimes the case that you change the visibility of an instance
variable to suit your needs. In Objective-C, there is rarely a reason to do this, so it's really
more trivia than anything. (The one case where @private is used is when framework
developers write classes that will be subclassed. This prevents the subclass from modify-
ing a variable directly, and is typically done because the code in the setter method for that
variable needs to be executed for things to work out okay. Public instance variables are
generally considered a bad idea.)
Finishing the BNR feed
Now that an RSSChannel can be copied, you can create the third instance of
RSSChannel for the store to use for merging the cached and new feeds. In
BNRFeedStore.m , update fetchRSSFeedWithCompletion: .
if (!cachedChannel)
cachedChannel = [[RSSChannel alloc] init];
RSSChannel *channelCopy = [cachedChannel copy];
[connection setCompletionBlock:^(RSSChannel *obj, NSError *err) {
if (!err) {
[cachedChannel addItemsFromChannel:obj];
Search WWH ::




Custom Search