Can't use Swift classes inside Objective-C

前端 未结 25 2473
野趣味
野趣味 2020-11-22 08:10

I try to integrate Swift code in my app.My app is written in Objective-C and I added a Swift class. I\'ve done everything described he

25条回答
  •  眼角桃花
    2020-11-22 08:23

    @sig answer is one of the best, however, it did not work for me with the old project (not new!), I needed some modifications. After a lot of variations I found the recipe for me (using XCode 7.2):

    1. Product Module Name : $(PRODUCT_NAME:c99extidentifier)
    2. Defines Module : NO
    3. Embedded Content Contains Swift : NO
    4. Install Objective-C Compatibility Header : YES
    5. Objective-C Bridging Header : ProjectName-Bridging-Header.h

    The last point (5) was crucial. I put it only on the second section (Targets field), the Project field should be left empty: Otherwise, it did not generate the right "Project-Swift.h" file for me (it did not include swift methods).

提交回复
热议问题