1
votes

Im using a custom made class with delegate methods written in objective-c in a swift file. Bridging header is setup thus I am able to refer to classes in .m and .h files in .swift files. Here comes a problem, I was trying to include delegate method to the swift file, and it shows me message Type 'YourClassName' does not conform to protocol 'YourDelegateWrittenInObjC'. When I Command + Left Click on the error message, some message with gray background comes out on the delegate method.

Wish someone could help me solving this problem. A print screen is provided to help debug:

enter image description here

Edited (include delegate declaration):

Here you go:

@protocol CollapseClickDelegate
@required
-(int)numberOfCellsForCollapseClick;
-(NSString *)titleForCollapseClickAtIndex:(int)index;
-(NSString *)leftTitleForCollapseClickAtIndex:(int)index;
-(NSString *)rightTitleForCollapseClickAtIndex:(int)index;
-(UIView *)viewForCollapseClickContentViewAtIndex:(int)index;

@optional
-(UIColor *)colorForCollapseClickTitleViewAtIndex:(int)index;
-(UIColor *)colorForTitleLabelAtIndex:(int)index;
-(UIColor *)colorForTitleArrowAtIndex:(int)index;
-(void)didClickCollapseClickCellAtIndex:(int)index isNowOpen:(BOOL)open;

@end
1
It's clearly complainig about types. The types declared in your delegate methods are different from the one required by the objc class. Please post the objc protocol declaration.LombaX
I added to the question.L.C. Tan

1 Answers

4
votes

Swift primitive types (like Int) are automatically bridged to NSNumber when interacting with Objective C.

When you write Int on the Swift side, you must have an NSNumber on the Objective C side.

Since your objc protocol use int (a c primitive type) and not NSNumber as the type of some parameters/return value, you should bridge it with the correct type, that is CInt

Change all your Int with CInt on the Swift side and all will work

You can read more here