简体   繁体   中英

How to detect if variable type is CGColor

I'm having this issue, that on old react native versions borderColor is CGColorRef and on new one it's UIColor .

Is there a way to check CGColorRef variable type? Objective-c doesn't allow me to use isKindOfClass with CGColorRef .

What I'm trying to achieve:

if([rctView.borderColor isKindOfClass:[UIColor class]]) { // that's where I'm wrong
   _borderColor = rctView.borderColor; // assign UIColor to UIColor variable
} else {
   _borderColor = [UIColor colorWithCGColor:rctView.borderColor]; // assign converted CGColor to UIColor
}

Thanks.

There is noway to make it out. UIColor belongs foundation, CGColorRef is derived from CFTypeRef, belongs to corefoundation. a method in foundation or corefoundation can not be used in the other. that means you can't use foundation's or corefoundation's method to detect the variable type. below the foundation and corefoundation, there is some method to use in both, but in that level, the variable just means a memory address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM