iOS Question Call B4i sub from inline OBJC and return value

CaptKronos

Active Member
Licensed User
How would I call from inline OBJC a B4i sub such as the following and have the inline code receive the sub's return value:
B4X:
sub test as int
   return 1
end sub
Thanks.
 

CaptKronos

Active Member
Licensed User
Do you mean like this:
B4X:
sub test as int
   return 1
end sub

#If OBJC 

-(NSInteger)testGettingVal
{
    NSInteger aNum;
    aNum=[self.bi raiseEvent:nil event:@"test:" params:@[]];
    return aNum;
}

#end if
I always get a value of 0 returned. I thought raising an event returned immediately (hence 0 rather than 1 being returned).
 

Erel

Administrator
Staff member
Licensed User
Your objective C code is wrong. What are you using inline code for?
 

Erel

Administrator
Staff member
Licensed User
There is an extra colon in the in the sub name. There are other problems with this code (you will probably see a warning about unexpected synchronous event in the logs).
 

CaptKronos

Active Member
Licensed User
Yes, sorry, you are correct. I rewrote my code on the fly to simplify it for the post and I missed the ":". My original code was passing a parameter. I also get the unexpected synchronous event message in the logs. However, I can't use raiseUIEvent because I believe that doesn't return a value.
 

Semen Matusovskiy

Well-Known Member
Licensed User
I know nothing about Objective C. But, as I understand, inline OBJC allows direct calls like in other languages. For example, I added some statements in Erel's sample (see test.zip).
 

Attachments

Top