mulle-objc / MulleObjC

💎 A collection of Objective-C root classes for mulle-objc
https://www.mulle-kybernetik.com/mulle-objc
Other
51 stars 6 forks source link

Calling a +method using [self class] is clumsy #9

Open mulle-nat opened 5 years ago

mulle-nat commented 5 years ago

You used to be able to call isa and maybe this should become a keyword just like self (again).

mulle-nat commented 5 years ago

To clarify:

- (void) clone
{
   id clone;
   clone = [[self class] new];
}

is lame when you could write

- (void) clone
{
   id clone;

   clone = [isa new];
}

The problem is that isa used to be a struct member, but could should be elevated to keyword status.

hsnamr commented 5 years ago

Why not call it instancetype instead of isa? More ObjC are familiar with instancetype keyword and I think it makes sense to use it in this context.

I would like to investigate this and see if I can figure it out.

mulle-nat commented 5 years ago

instancetype is a compiler construct. It's not a real type. F.e. you can't do @encode( instancetype). I hope that helps 😃

hsnamr commented 5 years ago

I reviewed this repository and I am not sure where do I need to make the change to add isa as a keyword. Is the source code in this repository or another repository?

mulle-nat commented 5 years ago

The general idea of the library structure is, that MulleObjC is based on mulle-objc-runtime, and does the runtime specific stuff (i.e. NSObject).

mulle-objc-compat is a layer on top of mulle-objc-runtime, to emulate and translate Apple runtime functions like object_getClass to mulle_objc_object_get_isa for instance.

Finally objc-compat contains various "stuff" to write compatible code, where the Apple Foundation and the MulleFoundation differ.

So its debatable if isa would be part of mulle-objc-compat or objc-compat.

Anway...

I probably should close this issue, since I have added a #define isa to objc-compat a few weeks ago. This isn't part of the 0.14 release yet, though.

The 0.15 release will be a fairly big step towards compatibility of MulleFoundation with the Apple Foundation, albeit it's not in a release-worthy state just now unfortunately.