I'm trying to add a custom declaration to my def f...
# kotlin-native
d
I'm trying to add a custom declaration to my def file to help aid cinterops with a mocking library for iOS. The method is as follows
Copy code
_Nullable id verify(id mock) {
     return  MKTVerifyWithLocation(mock, self, __FILE__, __LINE__);
}
cinterops throws
error: use of undeclared identifier 'self'
. Is cinterops not able to handle the
self
keyword yet or is there another way I should be handling this?
o
Did you mention that language is Objective-C in your . def file?
d
Yes
Full file:
Copy code
language = Objective-C
headers = OCMockitoIOS.h
compilerOpts = -framework OCMockitoIOS
linkerOpts = -framework OCMockitoIOS

---
#import "MKTOngoingStubbing.h"
#import "NSInvocation+OCMockito.h"
#import "MKTMockitoCore.h"

MKTOngoingStubbing* given2(id testCase, id methodCall) {
    return [[MKTMockitoCore sharedCore] stubAtLocation:MKTTestLocationMake(testCase, __FILE__, __LINE__)];
}

_Nullable id verify2(id mock) {
     return  MKTVerifyWithLocation(mock, self, __FILE__, __LINE__);
}
o
Can this program be compiled by clang compiler?
d
Haven't tried, but I believe it should be. Essentially, Im just trying to expose the following
#define
to kotlin https://github.com/jonreid/OCMockito/blob/master/Source/OCMockito/Core/OCMockito.h#L216
I worked around it by going a level deeper into the code and implementing passing in the class itself, but was still curious about cinterops giving an error on
self
.
o
There shall be no difference to what clang does, if program is legit objective-c - it shall compile. And here it seems there’s no class context for self to exist.
d
Ahhh, gotcha.
s
Why do you expect
self
available not in an Objective-C method?
d
I took that to mean that
self
is not available at the time cinterops does its conversion.
s
self
is not available in simple top level functions in Objective-C. It is available only in Objective-C methods.
d
Thanks for the clarification 👍