objective-c - 从 Objective-C 迁移到 Swift 并删除已转换的 Objective-C 文件

标签 objective-c swift

如何删除 Xcode 项目中已迁移的 Objective-C 文件?函数 main.m 可以访问 Swift 函数,但我必须保留已转换为 Swift 等效项的 .h 和 .m 文件吗?

我能够将 Objective-C 类转换为 Swift 类。然后我从 main.m 访问了 Swift 函数。

以下是 .h 和 .m 文件:

@interface SimpleClassObject:NSObject

-(void) IntVariableSent:(int)x;
-(int) MethodReturn: (int)y;

@end;

下面是.m文件

@implementation SimpleClassObject

-(void) IntVariableSent:(int)x
 {
     NSLog(@"The value of x = %d was passed into this Objective C method", x);
 }

-(int) MethodReturn: (int)y
{
    int multiply = 3;

    multiply *= y;
    NSLog(@"An integer was passed to MethodReturn of y = %d", y);

    return multiply;
}

@end

下面是 Swift 类:

class SimpleClassObject2: NSObject {
    func intVariableSent(_ x: Int) {
        print("The value of x = \(x) was passed into a Swift function")
    }

    @objc func methodReturn(_ y: Int) -> Int {
        var multiply: Int = 3
        multiply *= y
        print("An integer was passed to methodReturn of y = \(y)")
        return multiply
    }
}

下面是main.m

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        int valueReturnedFromFunction;

        SimpleClassObject2 *swftObj = [[SimpleClassObject2 alloc]init];
        [swftObj passNothingReturnNothing];
        [swftObj intVariableSent:90];
        valueReturnedFromFunction  = (int)[swftObj methodReturn:80];
        printf("\n%d value using Swift class\n\n", valueReturnedFromFunction);
    }
    return 0;
}

最佳答案

在与 Xcode 项目解除关联后,我刚刚删除了 Objective C 文件。因此 MikeIOSMike 是正确的。感谢 MikeIOSMike 的回复

关于objective-c - 从 Objective-C 迁移到 Swift 并删除已转换的 Objective-C 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50544270/

相关文章:

swift - Swift 中的委托(delegate)示例

ios - SetDelegate 导致 'unrecognized selector' 异常

iphone - UITextView 的奇怪问题

objective-c - 为什么我的核心数据教程应用程序打开时出现黑屏且没有表格 View ?

ios - 调整设备尺寸的 UILabel 字体大小

ios - 转至聊天 View Controller

objective-c - 即使在 macOS 应用程序的窗口之外也能永久检测 3 指平移手势

python - OSX swift 没有名为 6 的模块

swift - 自定义 TableView + 段 Controller 代码中的格式和错误

ios - UITableView 不填充 UITabBarController 内的自定义单元格