打压的方法已过时警告时,有没有它的替代(Suppress warning for deprecate

2019-10-19 02:39发布

我在一个项目实现了这个自定义类: https://github.com/wimagguc/ios-custom-alertview

但是Xcode中给出了“initWithParentView”已被弃用警告。

- (id)init
{
    return [self initWithParentView:NULL];
}

我一直没能找到一个替代这种方法,而类的工作出色。 谁能告诉我如何禁止这种警告或者告诉我替代“initWithParentView”?

Answer 1:

请阅读更改说明它清楚地说,使用init方法

编辑:因为它会在无限循环使用[super init]而不是[self init]

- (id)init
{
   // return [self init]; 
      return [super init];
}


Answer 2:

它看起来像开发商标明这是不推荐使用,并使用init方法建议。 您可以编辑第三方库删除此属性或抑制它。 也许移动initWithParentView的内容到INIT将是图书馆的一个更好的定位。

/*!
 DEPRECATED: Use the [CustomIOS7AlertView init] method without passing a parent view.
 */
- (id)initWithParentView: (UIView *)_parentView __attribute__ ((deprecated));


Answer 3:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void) methodUsingDeprecatedStuff {
    //use deprecated stuff
}
#pragma clang diagnostic pop

这应该镇压。



Answer 4:

那么,类的* .h告诉你该怎么做

/ *! 弃用:使用[CustomIOS7AlertView INIT]方法没有通过父视图。 * /

所以,如果你重写自定义类只使用

[self init];

其他使用

[[CustomIOS7AlertView alloc] init]


文章来源: Suppress warning for deprecated method when there's no alternative for it