iOS Question Rules regarding multiple inline objc code blocks?

Sandman

Expert
Licensed User
Longtime User
I've spent a couple of hours debugging why an inline code block didn't work. (It failed with "Method not found".)

Then I realized I had another block earlier in the file, so on a chance I just moved them so they were together (but not in same #if objc) - and then it worked right away.

After realizing this I tried finding info about it on the forum, and failed. Does anyone know what the "rules" are for having multiple inline objc code blocks?
 

Sandman

Expert
Licensed User
Longtime User
My guess is that one of the blocks implemented a new class and "closed" the previous one (started with @end).

One of the blocks does contain two @end, it is from one of your examples:

B4X:
#if objc
- (NSObject*)createCircularRegion:(double)lat :(double)lon :(double)radius :(NSString*)identifier {
    return [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(lat, lon) radius:(CLLocationDistance)radius identifier:identifier];
}
@end
@interface B4ILocationManager (beacon) 
@end

@implementation B4ILocationManager (beacon)

- (void)locationManager:(CLLocationManager *)manager 
          didExitRegion:(CLRegion *)region {
          [B4IObjectWrapper raiseEvent:self :@"_regionexit:" :@[region]];
    }
- (void)locationManager:(CLLocationManager *)manager 
         didEnterRegion:(CLRegion *)region {
        [B4IObjectWrapper raiseEvent:self :@"_regionenter:" :@[region]];
}
- (void)locationManager:(CLLocationManager *)manager 
monitoringDidFailForRegion:(CLRegion *)region 
              withError:(NSError *)error {
    NSLog(@"Error: %@", error);
    [B4IObjectWrapper raiseEvent:self :@"_statechanged:" :@[@(3)]];
}
- (void)locationManager:(CLLocationManager *)manager 
didStartMonitoringForRegion:(CLRegion *)region {
    NSLog(@"Start monitoring: %@", region);
}
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)State forRegion:(CLRegion *)region {
   NSLog(@"didDetermineState: %@", @(State));
   [B4IObjectWrapper raiseEvent:self :@"_statechanged:" :@[@(State)]];
}

#End If

When in doubt, check the generated Objective C modules.

Ok, I tried that now, and then I tried changing the order of the blocks. Sure, they switched place in the generated file, but I couldn't see anything that seemed obviously wrong. That said, I know next to nothing about ObjC, so that might be the problem of course.

Would it be possible to summarize the situation with a rule? Something like "If an inline objc block contains @end it must also contain X", or something like that?
 
Upvote 0
Top