This repository has been archived by the owner. It is now read-only.

Constructor return type #26

Merged
merged 3 commits into from Dec 3, 2012

Conversation

Projects
None yet
2 participants
@jackhl
Copy link
Contributor

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

README.md Outdated
@@ -32,6 +32,7 @@
void GHAwesomeFunction(BOOL hasSomeArgs);
```

* Constructors should return `instancetype` rather than `id`.

This comment has been minimized.

@jspahrsummers

jspahrsummers Dec 2, 2012

Contributor

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

This comment has been minimized.

Copy link
Contributor

jspahrsummers commented Dec 2, 2012

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

This comment has been minimized.

Copy link
Contributor

jackhl commented Dec 2, 2012

Good point. Fixed in 5306962.

@jspahrsummers

This comment has been minimized.

Copy link
Contributor

jspahrsummers commented Dec 3, 2012

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.