MobiVM / robovm

Ahead of time compiler for JVM bytecode targetting iOS, Mac OSX and Linux
https://mobivm.github.io
967 stars 133 forks source link

NSNotificationCenter addObserverForName returns NSObjectProtocol, but remove only accepts NSObject #629

Closed LordTylus closed 2 years ago

LordTylus commented 2 years ago

Please ensure you have given all the following requested information in your report.

Issue details

I just tested out the 2.3.16-SNAPSHOT and was given compilation errors that the following Method:

@Method(selector = "addObserverForName:object:queue:usingBlock:")
    public native NSObjectProtocol addObserver(NSString name, NSObject obj, NSOperationQueue queue, @Block VoidBlock1<NSNotification> block);

now returns an NSObjectProtocol compared to the NSObject which was still current in 2.3.15

While fixing it, i noticed, that the resepctive removeObserver Methods still take an NSObject as parameter, not an NSObjectProtocol.

    @Method(selector = "removeObserver:")
    public native void removeObserver(NSObject observer);
    @Method(selector = "removeObserver:name:object:")
    public native void removeObserver(NSObject observer, NSString name, NSObject anObject);

So effectively I dont have any way of removing this observer anymore.

According to the discussion in gitter I got the following information from @dkimitsa

- (id<NSObject>)addObserverForName:(NSNotificationName)name 
                            object:(id)obj 
                             queue:(NSOperationQueue *)queue 
                        usingBlock:(void (^)(NSNotification *note))block;

its a bit messy. id is being mapped to NSObject. Right way is to map it to ObjCObject.
But then we will not be able to use returned NSObjectProtocol with ObjCParameter.
Probably we will have to return it back to be NSObject in both returned type and param. But its against protocol (as returned type might be not NSObject class instance)

This should probably be fixed, before 2.3.16 gets released.

Build Tools:

Versions:

Please provide the version of RoboVM, XCode and JDK used

dkimitsa commented 2 years ago

@LordTylus could you please update regarding this issue. it was part of 2.3.16 release. thx

LordTylus commented 2 years ago

@dkimitsa Ahh yes, I had tested that in the snapshot before release, worked again, so will close