Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating NSInteger category

When trying to create a category for NSInteger, the compiler complains that it "Cannot find interface declaration for 'NSInteger'". Is it not possible to create an NSInteger category?

A simple test will show the compiler error:

#import <Foundation/Foundation.h>

@interface NSInteger (NSInteger_Extensions)

-(NSInteger)simpleTest;

@end



#import "NSInteger_Extensions.h"

@implementation NSInteger (NSInteger_Extensions)

-(NSInteger)simpleTest {
    return self + 5;
}

@end

Should this be possible?

Thanks!

like image 706
Hooligancat Avatar asked Apr 16 '26 05:04

Hooligancat


1 Answers

NSinteger is not an interface. So it's not possible.

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html

From the link above:

Used to describe an integer.

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
#else
typedef int NSInteger;
#endif

PS: But you can make a category of NSNumber. I think it's the thing you want to do

like image 123
Andrew Avatar answered Apr 19 '26 00:04

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!