Coder Social home page Coder Social logo

objc-zen-book's People

Contributors

14lox avatar albertodebortoli avatar altyus avatar barksten avatar bryanjclark avatar cconstable avatar guillaumealgis avatar khanghoang avatar luca-bernardi avatar qianyanseu avatar seanoshea avatar vinhnx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

objc-zen-book's Issues

`mutableCopy` addtion

Although NSMutableArray *aMutableArray = [@[] mutableCopy]; is not recommended, the code below is appropriate:

NSMutableDictionary *aMutableDictionary = [@{@"Key":@"Value",
                                             @"AnotherKey":@"OtherValue",
                                             @"SomeOtherKey":@"SomeOtherValue"} mutableCopy];

if (SomeThingWrong) {
    aMutableDictionary[@"Error"] = @"ErrorDescription";
}

Private _methods

You state that private methods should never be prefixed with a single underscore, but the section about use of the pragma directive includes an example of a private method thusly declared:

#pragma mark - Private

- (void)_privateMethod { /* ... */ }

That's a little off-putting in an otherwise excellent guide.

const var NotificationName should not use static

In the section of https://github.com/objc-zen/objc-zen-book#constants, we should not use static for NotificationName, or we can' t extern it for other code. For example:

//a.h
extern static NSString *const TestConstNotificationName;
//a.m
static NSString *const TestConstNotificationName = @"TestConstNotificationName";

This won't pass compile.

On other hand, a constant will be init in the global memory area. So it doesn't need a static key word.

Why __strong __typeof(weakSelf)strongSelf = weakSelf ?

I know this project is about coding convention, but you tried to explain block and its usage, so I ask

In the "Block" section,

__weak __typeof(self)weakSelf = self;
__strong __typeof(weakSelf)strongSelf = weakSelf;

Why typeof(weakSelf) instead of typeof(self)? Aren't they the same thing ?

Protocol Discussion incorrectly associates Protocols with Abstract Classes

In the section on protocols, the book states:
"A great miss in the Objective-C world is the outcome of the latest decades about abstract interfaces. The term interface is typically used to refer to the .h file of a class but it has also another meaning well known to Java programmers which is basically used to describe to a set of methods not backed by a concrete implementation. "

This is not accurate. In objective-c class clusters provide abstract interfaces (and are, usually, abstract factories). NSString, NSNumber, etc. are all abstract interfaces implemented as class clusters. Several framework classes allow specific class clusters to be extended at runtime (NSURLProtocol, etc.).

https://developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/ClassCluster.html

In contrast, a protocol only defines a set of messages that an object can choose to implement.

https://developer.apple.com/library/ios/documentation/general/conceptual/devpedia-cocoacore/Protocol.html#//apple_ref/doc/uid/TP40008195-CH45-SW1

Exploit Code Block: Code error

clang version: Apple LLVM version 8.0.0 (clang-800.0.42.1)
Xcode version: 7.3.1

NSURL *url = ({
    NSString *urlString = [NSString stringWithFormat:@"%@/%@", baseURLString, endpoint];
    [NSURL URLWithString:urlString];
});

compiler error: initializing 'NSURL *__strong' with an expression of incompatible type 'void'

The value of the latest statement is not returned if enclosing in round bracket.

#### Secondary Initializer

This imply that in your designated initializer you should always call another secondary initializer or your self designated initializer.

Do you mean:

This imply that in your secondary initializer you should always call another secondary initializer or your self designated initializer. ?

Another way to add object to immutable collection

Hi, with KVC, we have another option mutableArrayValueForKey, mutableSetValueForKey to add object to the immutable collection

Extract from the Core Data 2nd book, section Mutable Access of To-Many Relationships

You might notice that the NSSet we get back when accessing a to-many rela- tionship is immutable. Adding an object to a to-many relationship with an immutable NSSet requires creating a mutable copy of the NSSet, adding the new object to the NSMutableSet, and setting the NSMutableSet back onto the parent object. It’s a painful process and, fortunately, unnecessary. When we want to add an object to a to-many relationship, we can use -mutableSetValueForKey: in the place of -valueForKey:. This returns an NSMutableSet for us that is already associated with the parent object and reduces our code to the following:

NSManagedObject *newIngredient = ...;
NSManagedObject *recipe = ...;
NSMutableSet *ingredients = [recipe mutableSetValueForKey:@"ingredients"]; 
[ingredients addObject:newIngredient];

Note that we did not need to set the NSMutableSet back into the entity, and therefore the code to add an object to a to-many relationship is quite short

What do you think?

Say you have a class like this

@interface User
@property (nonatomic, strong) NSArray *books;
@end

How do you add an object to books?

Bad example in Properties/Mutable-object

The sentence:

Any property that potentially can be set with a mutable object (e.g. NSString,NSArray,NSURL) must

implies that NSURL have a mutable counterpart. Unless I have missed something, that's not the case and NSURL should be omitted from the example.

Class name - Unclear sentence

In # Class > ## Class name:

There is another good practice that you might want to follow while choosing while naming you class that is, when you're creating a subclass

Assigning self in init

You wrote:

The interesting part is that the init implementation of NSObject is simply returning self, this is because the variable self is written after the alloc method where all the initialization logic is done.

I think this is not correct or at least confusing. There is nothing special happening between alloc and init that causes “the variable self is written after the alloc method”. alloc simply returns a pointer to the memory it allocated. By sending any message (init or not) to this pointer, objc_msgSend() assigns it to self in the context of the method that was called.

This is also needed to allow the NSObject's subclass to follow the previously exposed pattern.

I donʼt understand what you mean by this sentence.

There is another important part of the contract with init: the method can (and should) signal to the caller that it wasn't able to successfully finish the initialization by returning nil;

Correct. There is another reason why self = [super init] is necessary. Initializers are allowed to return a different instance than the one they have been called on. This is done by re-assigning self in the initializer. Some Cocoa classes use this to return the same instance for identical (immutable) objects. For example, allocating two NSNumbers with the same value (say, @3.14 and @3.14) will return the same instance (ignoring tagged pointers for the moment).

Private method with _ prefix.

Never prefix your private method with a single underscore _

- (void)_notifyDelegates {

The two lines above are just copied here.

search return 5;

- (void)giveMeFive 
{
    NSString *foo;
   #pragma unused(foo);
   return 5;
}

replace

- (NSInteger)giveMeFive 
{
    NSString *foo;
   #pragma unused(foo);
   return 5;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.