iOS Question Rules regarding multiple inline objc code blocks?

Discussion in 'iOS Questions' started by Sandman, Dec 18, 2018.

Tags:
  1. Sandman

    Sandman Well-Known Member Licensed 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?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't matter whether they are in the same block or not.

    My guess is that one of the blocks implemented a new class and "closed" the previous one (started with @end).
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    When in doubt, check the generated Objective C modules. They are available in the Objects folder.
     
  4. Sandman

    Sandman Well-Known Member Licensed User

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

    Code:
    #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
    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?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    1. The first @end closes the main class.
    2. The last class shouldn't be closed.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice