【问题标题】:ARC restriction - Implicit conversion of 'char' to 'NSString *' is disallowed with ARCARC 限制 - ARC 不允许将 'char' 隐式转换为 'NSString *'
【发布时间】:2012-03-07 09:45:57
【问题描述】:

我正在使用 mapkit 并设置一些注释。在我的代码中某处我有:-

#define ANNOTATION_FIRST_TYPE 1

unsigned char annoType = ANNOTATION_FIRST_TYPE

annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:annoType ];

上面最后一行抛出错误Implicit conversion of 'char' to 'NSString *' is disallowed with ARC,这很公平,我需要将annoType显式更改为NSString。

但奇怪的是;如果对于第 (3) 行,我有以下内容:-

annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:**ANNOTATION_FIRST_TYPE**]; 

它编译没有错误? 问题是,ANNOTATION_FIRST_TYPE 的类型是什么?

【问题讨论】:

  • 下次请处理您的代码格式。

标签: objective-c automatic-ref-counting constants c-preprocessor


【解决方案1】:

ANNOTATION_FIRST_TYPE 是一个整数。整数可以隐式转换为 C 中的指针,但如果您启用了警告,编译器应该会警告您这一点。我不知道为什么这不是编译器错误,可能只是疏忽。

您应该将 ANNOTATION_FIRST_TYPE 定义为 NSString,例如

#define ANNOTATION_FIRST_TYPE @"1" 

【讨论】:

  • 好奇地 [_mapView dequeueReusableAnnotationViewWithIdentifier:1];无法按预期编译。我一直认为指令预处理器只是进行替换替换,在这种情况下它似乎做得更多。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多