0

我得到了 XCode 标签ARC Issue,我很难解析。我有这堂课:

typedef void (^sig_cb_t)(NSString *parm);

@protocol Signaleer
// <snip>
-(void) connect:(NSString *) verb
          parm:(NSString*) param
      callback:(sig_cb_t)callback;
@end

// In another header:
@interface Switchboard : NSObject <Signaleer> {
   @private
   NSMutableDictionary *bus;
}

// In init: method:
bus = [[NSMutableDictionary alloc] init];

// actual implementation:
-(void) connect: (NSString *)verb
           parm:(NSString*)parm
       callback:(sig_cb_t)callback {
  NSMutableArray *callbacks = [self.bus objectForKey:verb];
  NSArray *signal = [NSArray arrayWithObjects:callback, parm, nil];
  if (callbacks == nil) {
    NSArray *initial = [NSArray arrayWithObjects:signal, verb, nil];
    [bus setObject: initial, forKey:verb];
  } else {
    [callbacks addObject:signal];
  }
}

该行[bus setObject: initial, verb]导致错误No visible @interface for 'NSMutableDictionary' declares the selector 'setObject:'。谁能解释一下?

4

3 回答 3

1

I assume you are referring here to the line:

[bus setObject: initial, forKey:verb];

(you write [bus setObject: initial, verb] in the last line of your question which I assume is a mistake)

Both lines have a comma in there, which shouldn't be there.

于 2012-05-29T14:09:39.303 回答
0

You have a comma after initial. It should be:

    [bus setObject:initial forKey:verb];
于 2012-05-29T14:09:40.200 回答
0

从该方法调用中删除逗号,您将不再有错误。不需要逗号来分隔 Objective-C 中的普通参数列表

[bus setObject:initial forKey:verb];
于 2012-05-29T14:09:49.833 回答