警告:不推荐使用Objective-C对象中的函数定义

时间:2015-04-11 06:06:23

标签: ios xcode uikit objective-c-category

升级到Xcode 6.3后,我现在收到此警告:

Warning: Function definition inside an Objective-C object is deprecated

警告出现在NSString的一个类别中,我已经定义了UIKIT_STATIC_INLINE方法。

以下是有问题的代码:

// NSString+Helpers.h
#import <Foundation/Foundation.h>

@interface NSString (Helpers)

+ (BOOL)exampleCategoryMethod;

UIKIT_STATIC_INLINE NSString *NSStringFromCLLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
    return [NSString stringWithFormat:@"%f,%f", coordinate.latitude, coordinate.longitude];
}

@end

1 个答案:

答案 0 :(得分:6)

我只需将静态内联函数定义移到@interface之外。

以下是修改过的代码:

// NSString+Helpers.h
#import <Foundation/Foundation.h>

UIKIT_STATIC_INLINE NSString *NSStringFromCLLocationCoordinate2D(CLLocationCoordinate2D coordinate) {
    return [NSString stringWithFormat:@"%f,%f", coordinate.latitude, coordinate.longitude];
}

@interface NSString (Helpers)

+ (BOOL)exampleCategoryMethod;

@end