2

I have some problems with Protocols in Categories with clang compilier in Objective-C. I think clang ignore any protocols if this specified in Category, like in sample code below. If line "@interface MyClass() <MyProtocol>" is replaced to "@interface MyClass()" than object files is absolutely same (byte-to-byte).

#include <stdio.h>
#include <Foundation/Foundation.h>


@protocol Protocol1
@end

@protocol MyProtocol
@end


@interface MyClass : NSObject<Protocol1>
@end

@interface MyClass() <MyProtocol>
@end

@implementation MyClass
@end


int main() {
    if ([MyClass conformsToProtocol:@protocol(Protocol1)])
        printf("Protocol1 is conformed\n");
    if ([MyClass conformsToProtocol:@protocol(MyProtocol)])
        printf("MyProtocol is conformed\n");
    return 0;
}

I compilied this code on my Ubuntu and I got next output:

$ clang-3.5 -o main main.m -I `gnustep-config --variable=GNUSTEP_SYSTEM_HEADERS` -L `gnustep-config --variable=GNUSTEP_SYSTEM_LIBRARIES` -lgnustep-base -fconstant-string-class=NSConstantString -D_NATIVE_OBJC_EXCEPTIONS -lobjc
$ ./main
Protocol1 is conformed

But if this code is buid on OS X, I will get next ouput:

$ clang -o main main.m -lobjc
$ ./main
Protocol1 is conformed
MyProtocol is conformed

This problem is related with options -fobjc-runtime=gnustep and -fobjc-runtime=macosx, but I don't know why.

How can I fix this problem with gnustep environment? What can I do?

ferry
  • 21
  • 3

0 Answers0