20
votes

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'

1
Is it in a framework? Have you tested with other functions on the class? If it is in a framework, you will need to declare it as public.Chris Conover
Too vague. Show the actual declaration in Swift, the actual call in the Objective-C file, and the actual compiler message.matt
@chrisco I never declare any "public" type of thing, it seems vars or vals in swift class are default accessible as long as you are holding the object, am I right?harthoo

1 Answers

34
votes

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.