- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在 Xcode 9 上的 objective-c 项目中添加 swift 4 文件。为此,我正在执行以下步骤 -
第一步:假设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 上的问题?
最佳答案
我已经做了很多事情来解决这个问题,但我没有取得成功。但由于我的奉献精神,我终于解决了这个问题 -
Note : To access swift class in objective C code you have to use the @objec keyword along the class statement like that
@objc public class ShowAlertSwift: NSObject
首先创建一个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")
}
}
在 objectiveClass.h 中,我遵循了这些步骤
@class ShowAlertSwift
@interface ViewController : UIViewController
@end
此处无需再次定义接口(interface),因为该接口(interface)已经存在于“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];
}
同时在build设置中启用/更新这些属性 -
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
关于objective-c - 使用 Swift 4 在 Xcode 9 上找不到“ProjectName-Swift.h”文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46541792/
那么,如何在没有 /projectname/ 的情况下使用 ip:8080/projectname/* ,而只使用 ip:8080/ 呢? 已经尝试重定向所有内容,但这并不完全是我所需要的。 最佳答案
我看到对子项目的引用为 project(':projectName') {} 在$ projectRoot / build.gradle中 而且我还看到了对具有单独构建的子项目的引用,例如$ proj
我在使用此代码的操作方法中推送 View Controller 时发生崩溃 let vc = self.storyboard?.instantiateViewControllerWithIdenti
如何更改基本网址:http://Domain/ProjectName/web/index.php至 http://Domain/ProjectName在 Yii2 中。 最佳答案 你应该在基本模板/w
在运行程序时,它可以正常运行,但始终会引发此错误。它说错误来自行: int* temp = new int[length]; 我不知道为什么会这样。程序按升序返回数组,但随后抛出断点。 void me
创建模块而不复制文件时出现此错误settings.gradle : include ':libraries:ProjectB' project(':ProjectB').projectDir = ne
在我运行该程序后,我收到一条错误消息,指出 projectname 已触发断点。我仍然不知道错误是什么。我认为缺少一个成员函数,但有人可以帮助我吗? #include "AClass.h" #incl
当我尝试构建我的 Maven 项目时收到此警告。我搜索过谷歌但没有运气。这真的很烦人,因为我想发布我的项目,但它不会在这个警告下工作(我认为)。构建成功,但是当我尝试部署 war 文件时它不起作用(没
我是 mac 的新手,我收到如下错误 我应该怎么办我已经购买了开发者许可证并创建了供应证书,但我仍然面临这个问题。我不确定为什么会收到此错误任何帮助。 i have followed this you
我在 PodFile 中添加了新的 pod 并运行了命令 pod install 它删除了所有以前的 pod 并失败并出现以下错误 Unable to find a target named `Pro
我正在尝试构建 Preview对于基于 SwiftUI 构建的项目.起初,我创建了名为“VOIP”的项目。经过一段时间的开发和时间,我将它连接到 AppStore Connect并且项目名称的创建方式
我经常看到这种情况,这让我很困惑。 我总是直接在包的内容之后给包加上标题。例如,我的主类的路径从来不是“me.myproject.main.Main.class”,而只是“main.Main.clas
我遇到一个问题,每次我尝试构建项目时,构建状态栏都会挂起并显示“正在附加项目名称” 所以我尝试按照此处的说明进行操作:Attaching to ProjectName直接设置工程文件即可。 但问题是我
我在构建应用程序时弹出此对话框: projectName does not have an architecture that deviceName can execute. 我看过this ques
“@testable import”似乎没有导入原始项目中的所有文件。外部框架的文件作为单独的文件添加到原始项目中,除非检查“目标成员资格”以进行单元测试,否则测试用例似乎无法访问它们。奇怪的是,单元
我的 iOS 程序中出现 EXC_BAD_ACCESS,我怀疑原因出在我的一个匿名 block 中,但其中有很多,我需要稍微缩小候选列表的范围。 堆栈跟踪将当前帧显示为 __lldb_unnamed_
我正在使用 Git,当我尝试使用 XCode 的源代码控制菜单从我当前的分支中提取一个更新的开发分支时,我收到了这个错误消息: The operation could not be performed
我正在尝试运行由 MSBuild 生成的 ProjectName.deply.cmd 当参数 /p:DeployOnBuild=True通过。参数“ComputerName”之一将作为 https:/
我正在使用 Visual Stduio 2015 社区版。我已经加载了一个 C# 项目并希望将其配置为使用影子构建,这样源文件就不会与任何二进制文件或中间构建文件混淆。尝试使用 VS UI 设置 C#
我不确定我是否正确理解了 Sonar 扫描仪分析中参数 ProjectKey、ProjectName 和 branch 的使用。 假设我有一个具有不同分支的项目。当我独立于分支运行分析时,Projec
我是一名优秀的程序员,十分优秀!