简体   繁体   中英

Error in the “Objective-C Generated Interface Header Name”

I've been upgrading my project to Swift2. After resolving many errors, i got an error when i build the project.

The error is located in the Objective-V Generated Interface Header ,

Xcode is printing this error Type argument 'CGColorRef' (aka 'struct CGColor *') is neither an Objective-C object nor a block type

Here is the code, the error is printed on the line between the **:

SWIFT_CLASS("_TtC519RadialGradientLayer")
@interface RadialGradientLayer : CALayer
**@property (nonatomic, copy) NSArray<CGColorRef> * __nullable colors;**
@property (nonatomic, copy) NSArray<NSNumber *> * __nullable locations;
@property (nonatomic) CGPoint center;
@property (nonatomic) CGFloat startRadius;
@property (nonatomic) CGFloat endRadius;
- (nullable instancetype)initWithCoder:(NSCoder * __nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithLayer:(id __nonnull)layer OBJC_DESIGNATED_INITIALIZER;
- (void)drawInContext:(CGContextRef __nonnull)ctx;
+ (BOOL)needsDisplayForKey:(NSString * __nonnull)key;
@end

I guess that is link to this class

class RadialGradientLayer: CALayer {

    var colors: [CGColor]? {
        didSet {
            self.setNeedsDisplay()
        }
    }

    var locations: [CGFloat]? {
        didSet {
            self.setNeedsDisplay()
        }
    }
    ...
}

I didn't found any answer anywhere or even a clue so here i'm.

the error is trying to tell you that you can't have an NSArray contain primitive types.

you would get a similar error if you attempted to do something like this:

@property (nonatomic, strong) NSArray <Int>* intArray;

one way to fix this would be to make your swift class hold an array of UIColor instead of CGColor .

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