MulleObjC icon indicating copy to clipboard operation
MulleObjC copied to clipboard

Calling a +method using [self class] is clumsy

Open mulle-nat opened this issue 5 years ago • 5 comments

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

mulle-nat avatar Feb 13 '19 16:02 mulle-nat

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.

mulle-nat avatar Feb 15 '19 09:02 mulle-nat

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.

hsnamr avatar May 18 '19 00:05 hsnamr

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

mulle-nat avatar May 18 '19 09:05 mulle-nat

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?

hsnamr avatar May 18 '19 15:05 hsnamr

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.

mulle-nat avatar May 18 '19 16:05 mulle-nat