Can't use Swift classes inside Objective-C

前端 未结 25 2348
野趣味
野趣味 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

    In my case, apart from these steps:

    1. Product Module Name : myproject
    2. Defines Module : YES
    3. Embedded Content Contains Swift : YES
    4. Install Objective-C Compatibility Header : YES
    5. Objective-C Bridging Header : $(SRCROOT)/Sources/SwiftBridging.h

    I have needed to put the class as public in order to create productName-Swift.h file:

    import UIKit
    
       @objc public class TestSwift: NSObject {
           func sayHello() {
              print("Hi there!")
           }
       }
    

提交回复
热议问题