Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objc code cannot find Bool variable defined in swift

Tags:

I have a var defined in one Swift file, but in another Objective-C file, when I try to set this var, the complier complains it cannot find the var. How do I solve this problem? here is the code: in swift:

var isCreating: Bool!

in objc :

SelectMemberViewController *ctrl = [[SelectMemberViewController alloc]init];
ctrl.isCreating = YES

then the complier is complaining : Property 'isCreating' not found on object of type 'SelectMemberViewController'

like image 374
harthoo Avatar asked Nov 08 '14 02:11

harthoo


People also ask

How do you declare a boolean in Swift?

Swift recognizes a value as boolean if it sees true or false . You can implicitly declar a boolean variable let a = false or explicitly declare a boolean variable let i:Bool = true .

What does @() do OBJC?

In Objective-C, any character , numeric or boolean literal prefixed with the '@' character will evaluate to a pointer to an NSNumber object (In this case), initialized with that value. C's type suffixes may be used to control the size of numeric literals.


1 Answers

The problem is that nothing in Objective-C's world corresponds to a Bool!. Thus, this declaration is not exposed to Objective-C. You need to declare this a plain Bool if you want Objective-C to be able to see it.

like image 140
matt Avatar answered Sep 21 '22 14:09

matt