小编Shu*_*Ain的帖子

使用Swift 4在Xcode 9上找不到'ProjectName-Swift.h'文件?

我正在尝试在Xcode 9的目标c项目中添加swift 4文件。为此,我正在按照以下步骤操作-

步骤1:假设swift类名称为ShowAlertSwift.swift

   import UIKit

    @objc public class ShowAlertSwift: NSObject {

    @objc func printSome() {
        print("Print line System")
    }
    @objc func test () {
        print("Test swift Class in objective C project")
    }
}
Run Code Online (Sandbox Code Playgroud)

步骤2:目标-c类首先声明@class ShowAlertSwift

在objectiveClass.h中,我遵循了以下步骤

@class ShowAlertSwift

@interface ShowAlertSwift: NSObject

-(void)test;
-(void)printSome;

@end

@interface ViewController : UIViewController

@end
Run Code Online (Sandbox Code Playgroud)

第3步-在ObjectiveClass.m中

#import "myproject-swift.h"

@interface UIViewController ()
{

}

@implementation
- (void)viewDidLoad
{
     ShowAlertSwift *alertObj = [[ShowAlertSwift alloc]init];
     [alertObj test];
}
Run Code Online (Sandbox Code Playgroud)

我还设置了以下属性

Defines modules - Yes
Embedded_Content_Contains_Swift - Yes …
Run Code Online (Sandbox Code Playgroud)

objective-c swift swift3 swift4 ios11

4
推荐指数
2
解决办法
4327
查看次数

如何使用swift 4在目标c类中符合swift类委托?

假设有两个类,一个在 swift 中,另一个在同一个项目中的objective-c 类中。

在 swift 类中,我声明了委托,我想在目标 c 类中设置该委托。

我已经这样做了以下方式...

import UIKit

@objc public protocol SwiftLoginVCDelegate: class {

}

@objc public class SwiftLoginViewController: UIViewController {

    @IBOutlet var txtUserName: UITextField!
    @IBOutlet var txtPassword: UITextField!
    @IBOutlet var btnLogin: UIButton!
    var delegate: SwiftLoginVCDelegate?

    override public func viewDidLoad() {
        super.viewDidLoad()
        self.txtPassword.text = "XYZ"
        self.txtPassword.text = "123"
        self.btnLogin.backgroundColor = UIColor.blue

    }
 @objc public func testObjective(){
        print("Swift class is integrated in objective c project")
    }
Run Code Online (Sandbox Code Playgroud)

目标 c 类是

#import "Mediator.h"

@class    SwiftLoginViewController;
@protocol SwiftLoginVCDelegate;

@interface LoginMediator …
Run Code Online (Sandbox Code Playgroud)

delegates objective-c ios swift4 ios11

4
推荐指数
1
解决办法
5761
查看次数

标签 统计

ios11 ×2

objective-c ×2

swift4 ×2

delegates ×1

ios ×1

swift ×1

swift3 ×1