New Reserved Word Issue in Xcode 8

Never had a problem with this until XCode 8 and Sierra. Method signature = "register:messageNamed:withBlock:". Nothing was flagged as an error, but the word “register” is red color in XCode 8. DoubleClick will not link to it. The routine does not show in the menu methods list. No messages (MPC) were getting through.


Changing the method to "registerMsg:messageNamed:withBlock:" fixed it. This is very disconcerting because I never thought part of a message signature could cause something like this, and it permeates six apps we have in the app store. Lots of work and updates ahead to cure this.


Not sure if this should be considered a bug.

Replies

register is used in inline assembly calls.

Yup, I seem to remember that from my assembly coding days. I just didn't think it would be an issue as one part of an Objective C method signature. And it wasn't until now.

register
is a keyword in C-based languages (it’s a pointless keyword — modern compilers don’t need this sort of help — but a keyword nevertheless).

If I understand your post correctly, the compiler accepts your code even though it uses the

-register:messageNamed:withBlock:
selector, but Xcode’s syntax colouring, indexing, and so on have problems with it. Is that right?

If so, I’d definitely call that a bug and you should file it as such.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Basically, "yes". But not just the coloring and indexing. The calls were not producing results. I have my own messaging system, allowing individual objects to register to receive messages, and then have their (stored) block called if that (MPC) message is received. That quit working entirely with XCode8/Sierra until I changed "receive" to "receiveMsg" in the method signature. Simple example on the Mac side:


- (void) registerForMessages {


[self.mc registerMsg:self messageNamed:kMCMsgKeyPresImageRequest withBlock:^(NSDictionary *info) {

// This one did not require "info", which, in general, could contain any relevant data..

[self sendTheCapturedImage];

}];


// Regiter for other messages.

}


"mc" is the messageController where (MPC) messages are registered, sent, and received messages dispatched.

But not just the coloring and indexing. The calls were not producing results.

Weird. It’s hard to imagine how this would affect things at runtime. And I tried this with a test project here in my office (code pasted in below) and I didn’t see any problems.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
@import Foundation;

typedef void (^MessengerBlock)(NSDictionary * info);

@interface Messenger : NSObject

- (void)register:(id)target messageNamed:(NSString *)name withBlock:(MessengerBlock)block;

- (void)fireMessageNamed:(NSString *)name;

@property (nonatomic, strong, readonly ) NSMutableDictionary * registrations;
@end

@implementation Messenger

- (instancetype)init {
    self = [super init];
    if (self != nil) {
        self->_registrations = [[NSMutableDictionary alloc] init];
    }
    return self;
}

- (void)register:(id)target messageNamed:(NSString *)name withBlock:(MessengerBlock)block {
    self.registrations[name] = [block copy];
}

- (void)fireMessageNamed:(NSString *)name {
    MessengerBlock  block;

    block = self.registrations[name];
    if (block != nil) {
        block(nil);
    }
}


@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Messenger *    messenger;

        messenger = [[Messenger alloc] init];
        [messenger register:nil messageNamed:@"foo" withBlock:^(NSDictionary * info){
            NSLog(@"foo");
        }];
        [messenger fireMessageNamed:@"foo"];
    }
    return 0;
}