Can't access My Swift classes into Objective-C application

佐手、 提交于 2019-12-10 22:56:57

问题


I have created an application in Objective-C. I wants to use My Classes written in Swift into application for this i have done following things

  • set Defines Module to YES.
  • Defined Product Module Name

I created a swift file something like this MyClass.swift

import Foundation
class MyClass: NSObject
{
    override init() {
        super.init()
        print("SwiftClass init")
    }
}


@objc class SwiftClass : NSObject {

    override init() {
        super.init()
        print("SwiftClass init")
    }

    func sayHello() -> Void {
        print("hello");
    }

    func addX(x:Int, andY y:Int) -> Int {
        return x+y
    }

    // Make a dictionary
    // No, this code doesn't protect against values.count > keys.count
    func dictionaryWithKeys(keys:[String], andValues values:[String]) -> Dictionary<String,String> {

        var dictionary = Dictionary<String,String>()

        for var i = 0; i < keys.count; i++ {
            dictionary[keys[i]] = values[i]
        }

        return dictionary

    }

}

after successfully Clean & Build i have swift header file in my application named Testing-Swift.h as shown in pic -

I am able to import my header file in my ViewController.m but not able to access the classes written in swift -

Please help me .I am using Xcode 7.2


回答1:


Click on your Xcode Project file,click on Build Setting,find a search bar and Search "Defines module" and tick out "Yes". After search "PRODUCT MODULE,write Your Project name,rewrite in Your App delegates #Import "YourProjectName-swift.h"



来源:https://stackoverflow.com/questions/34524547/cant-access-my-swift-classes-into-objective-c-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!