Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Constructor return type #26

Merged
merged 3 commits into from Dec 3, 2012
Merged

Constructor return type #26

merged 3 commits into from Dec 3, 2012

Conversation

jackhl
Copy link
Contributor

@jackhl jackhl commented Dec 2, 2012

Constructors should use instancetype instead of id as their return type because methods that do not begin with one of the checked keywords (alloc, init, new, etc) will not get the same stricter type checking.

See http://clang.llvm.org/docs/LanguageExtensions.html#objc_instancetype

@@ -32,6 +32,7 @@
void GHAwesomeFunction(BOOL hasSomeArgs);
```

* Constructors should return `instancetype` rather than `id`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a space before this bullet, and a blank line after it? Otherwise, the "Expressions" section gets indented as if part of this line item.

@ghost ghost assigned jspahrsummers Dec 2, 2012
@jspahrsummers
Copy link
Contributor

Mostly 👍, but it's worth noting that instancetype isn't always appropriate. For example, a constructor added to NSValue probably shouldn't be instancetype, because that would imply that invoking it against NSNumber would return one (when it's probably intended to just return NSValue *).

Maybe it'd be worth adding a "generally" or something to the sentence to indicate that there might be exceptions.

@jackhl
Copy link
Contributor Author

jackhl commented Dec 2, 2012

Good point. Fixed in 5306962.

@jspahrsummers
Copy link
Contributor

Thanks! ⚡

jspahrsummers added a commit that referenced this pull request Dec 3, 2012
@jspahrsummers jspahrsummers merged commit d81cd0a into github:master Dec 3, 2012
@jspahrsummers jspahrsummers removed their assignment May 22, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants