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

dji*_*i33 0 xcode uikit ios objective-c-category

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

Warning: Function definition inside an Objective-C object is deprecated
Run Code Online (Sandbox Code Playgroud)

警告出现在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
Run Code Online (Sandbox Code Playgroud)

dji*_*i33 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
Run Code Online (Sandbox Code Playgroud)