Some properties of the Swift class were not found when accessing the Objective-c project

I am trying to bring Swift code into my old obj-c project. The Swift class is accessible from the obj-c class, but not all of its properties. for example

public var menuTitleColor: UIColor!

works fine but

public var cellHeight: CGFloat!

not found. I think this is because CGFloat is not an object. Is there a way to access this property without changing the Swift file?

+4
source share
2 answers

Primitive types in Objective-C

Look at this Swift class

@objc class Foo: NSObject {
    var myCGFloatOptional: CGFloat? = 1
    var myCGFloat: CGFloat = 1
}

If I use it in Objective-C, only the property is available myCGFloat.

Foo * foo = [Foo new];
foo.myCGFloat;
foo.myCGFloatOptional; // Compile Error

, Objective-C CGFloat (, float). Objective-C nil .

, Objective-C

float number = 1;
number = nil; // compile error

Objective-C UIColor!, Swift, UIColor - . , , UIColor .

Objective-C .

, int , Objective-C, , "",

int number = 1;
number = nil;

nil 0 ( , nil).

+3

:

public var cellHeight: CGFloat = 0 //(or some other number)

+1

Source: https://habr.com/ru/post/1618396/


All Articles