3

I've added XLForm, an Objective C library, to my Swift project using Xcode 6 beta 6.

The compiler trips on the method prototype of a protocol definition in XLFormDescriptorCell.h

#import <Foundation/Foundation.h>
...
@protocol XLFormDescriptorCell <NSObject>
...
@optional
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor;
  ^
  Parse Issue / Expected a type

Additionally a warning: "Semantic Issue: Conflicting return type in implementation of 'forDescriptorCellHeightForRowDescriptor:" 'id' vs 'CGFloat' (aka 'float')

To my project's Bridging-Header.h file I've added (although the parse error occurs whether I add this or not):

#import "XLForm.h"

which itself includes XLFormDescriptorCell.h

I can't see where XLForm returns an 'id'. Anyone come across this or something similar?

Matt
  • 9,068
  • 12
  • 64
  • 84
Carl
  • 2,896
  • 2
  • 32
  • 50

1 Answers1

9

CGFloat is declared at CoreGraphics/CGBase.h, which is imported by some headers imported at UIKit/UIKit.h, which is imported by default at most code files that Xcode creates for you, import it manually as needed.

As for return types mismatch, check the returned value at your implementation, make sure it returns precisely CGFloat, not NSNumber or anything else.

A-Live
  • 8,904
  • 2
  • 39
  • 74
  • Something is fundamentally broken. I added #import "CoreGraphics/CGBase.h" in the file with the compile error. The error went. And now 11! The Swift Compiler can't find declarations for NSObject, NSString, BOOL. I think that the order of includes in the XLForm has confused the compiler. – Carl Aug 29 '14 at 16:48
  • What error exactly do you see ? Don't forget to import Foundation header of ObjC where it is needed. – A-Live Sep 02 '14 at 07:50
  • I've moved on and looking at https://github.com/nicklockwood/FXForms as an alternative. – Carl Sep 02 '14 at 08:10
  • Whatever framework you are going to use the same rules apply, some headers might not have all imports they need because they are designed to be imported into environment where this basic frameworks are already imported. It is a bit more complicated when you combine two languages at the same project but the basics are always the same. – A-Live Sep 02 '14 at 09:53
  • "The same rules apply" - totally agree. Oddly, FXForms works smoothly. This is not to say that one is better written than the other; XLForm may just be the victim of beta Swift / Xcode 6 Beta 6 or another oddity. Either way, I got hit by this impasse (practice always overrules theory :) and have moved to FXForms. – Carl Sep 02 '14 at 09:59