如何删除 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/