Comments (1)
Probably I might not getting right the question but I will probably not have a class like the one you described.
I will rather do something like this:
@interface User
@property (nonatomic, readonly) NSArray *books;
- (void)addBook:(Book *)book
@end
@implementation User ()
@property (nonatomic, strong) NSMutableArray *mutableBooks;
@end
@implementation User
- (void)addBook:(Book *)book
{
[self.mutableBooks addObject:book];
}
- (NSArray *)books
{
return [self.mutableBooks copy];
}
@end
If you need or want to got for the extra mile inside addBook:
you can implement thread safety logic to access the mutable array from different thread.
Exposing the array interface breaks the encapsulation and let the user of the class to fiddle with you internal representation that can eventually change in the future.
from objc-zen-book.
Related Issues (19)
- Assigning self in init HOT 2
- NSNotification - Missing a rationale for the reverse DNS identifier HOT 3
- Add contributing guidelines
- Private _methods HOT 1
- Using NSHashTable as set of weak objects HOT 1
- Why __strong __typeof(weakSelf)strongSelf = weakSelf ? HOT 18
- Bad example in Properties/Mutable-object HOT 1
- Private method with _ prefix. HOT 3
- `mutableCopy` addtion HOT 2
- #### Secondary Initializer HOT 1
- Whatβs the license for the book? HOT 2
- search return 5;
- can you move it on Gitbook
- Exploit Code Block: Code error
- const var NotificationName should not use static
- Why "Indent using 4 spaces. Never indent with tabs."
- Protocol Discussion incorrectly associates Protocols with Abstract Classes
- Class name - Unclear sentence
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objc-zen-book.