nonopolarity
nonopolarity

Reputation: 151196

Can Objective-C code call C code and vice-verse? (mix and match them)

For example, can Objective-C call a C function, which calls Objective-C?

(UIColor *) getUIColorWithRGB(int r, int g, int b) {
    return [UIColor colorWithRed: r / 255.0 green: g / 255.0 blue: b / 255.0 alpha: 1];
}

@implementation UIColorCollection

+(UIColor *) lightCyanColor {
    return getUIColorWithRGB(224, 255, 255);
}

Upvotes: 0

Views: 175

Answers (1)

nhahtdh
nhahtdh

Reputation: 56829

If talking about possibility, it is possible. Just remove the brackets in the return value of the C function:

UIColor * getUIColorWithRGB(int r, int g, int b) {
    return [UIColor colorWithRed: r / 255.0 green: g / 255.0 blue: b / 255.0 alpha: 1];
}

Not sure whether this is OK as a programming practice, though.

Upvotes: 1

Related Questions