热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Swift4在Xcode9上找不到'ProjectName-Swift.h'文件?

如何解决《使用Swift4在Xcode9上找不到'ProjectName-Swift.h'文件?》经验,为你挑选了1个好方法。

我正在尝试在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")
    }
}

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

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

@class ShowAlertSwift

@interface ShowAlertSwift: NSObject

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

@end

@interface ViewController : UIViewController

@end

第3步-在ObjectiveClass.m中

#import "myproject-swift.h"

@interface UIViewController ()
{

}

@implementation
- (void)viewDidLoad
{
     ShowAlertSwift *alertObj = [[ShowAlertSwift alloc]init];
     [alertObj test];
}

我还设置了以下属性

Defines modules - Yes
Embedded_Content_Contains_Swift - Yes
Install Objective-C compatibility header - Yes
Objective C bridging header - $(SRCROOT)/Sources/SwiftBridging.h
Product Module Name - projectName

毕竟这些东西我得到像

1. myproject-swift.h file not found
2. Consecutive statement on a line must be seprated by ';'
3. failed to emit precompiled header '/Users/xyz/pqr/Trunk/build/SharedPrecompiledHeaders/myproject-Bridging-Header-swift_1CBSOZ0HA1Z9R-clang_UESSBOJR5CSH.pch' for bridging header '/Users/xyz/pqr/Trunk/OpenPage2/com/myProject/login/Login_iPad/myProject-Bridging-Header.h'

谁能知道如何解决Swift 4中Xcode 9上的问题?



1> Shubham JAin..:

我已经做了很多事情来解决这个问题,但是我没有成功。但是由于我的奉献精神,我终于解决了这个问题-

注意:要在目标C代码中访问swift类,您必须在类语句中使用@objec关键字,例如

 @objc public class ShowAlertSwift: NSObject

首先创建一个快速班

 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")
    }
}

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

    @class ShowAlertSwift

    @interface ViewController : UIViewController

    @end

此处无需再次定义接口,因为“ myproject-swift.h”文件中已存在该接口。请先参阅问题以清楚了解或参阅下文

@interface ShowAlertSwift: NSObject

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

@end

第3步-在ObjectiveClass.m中

#import "myproject-swift.h"

@interface UIViewController ()
{

}

@implementation
- (void)viewDidLoad
{
     ShowAlertSwift *alertObj = [[ShowAlertSwift alloc]init];
     [alertObj test];
}

同时在构建设置中启用/更新这些属性-

1. Defines Module set to YES (Mandatory on project - not on target)

2. Embedded_Content_Contains_Swift - Yes
3. Install Objective-C compatibility header - Yes
4. Objective C bridging header - $(SRCROOT)/Sources/SwiftBridging.h
5. Product Module Name - projectName


推荐阅读
author-avatar
冬日暖光816
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有