Ale*_*eem 9 xcode objective-c ios swift
我正在创建自己的框架,我添加了客观的c文件和它的工作正常后,我需要添加一些swift文件后添加swift文件xcode不给我选择自动创建桥接然后我遵循混合和匹配的方法.我遵循了我理解的一切.
我想访问swift文件到Objective c但是我收到了前向声明的错误所以这里是我附加的示例代码,请指导我在哪里做错了.
TestObjectCFile.h
#import <Foundation/Foundation.h>
@class TestSwiftFile;
@interface TestObjCFile : NSObject
@end
Run Code Online (Sandbox Code Playgroud)
TestObjectCFile.m
#import "TestObjCFile.h"
#import <TestFrameworkTry/TestFrameworkTry-Swift.h>
#import "TestFrameworkTry.h"
@implementation TestObjCFile
- (void)TestMethodForImportingSwiftFile
{
TestSwiftFile * testSwiftFile = [[TestSwiftFile alloc] init];
// TestSwiftFile * testSwiftFile = [self returnSwiftClassInstance];
NSLog(@"%@",testSwiftFile);
}
@end
Run Code Online (Sandbox Code Playgroud)
TestSwiftFile.swift
import Foundation
Run Code Online (Sandbox Code Playgroud)
并且错误发生在TestObjectCFile.m后面的行上.
TestSwiftFile * testSwiftFile = [[TestSwiftFile alloc] init];
Run Code Online (Sandbox Code Playgroud)
Ale*_*eem 22
最后我得到了解决方案 我做了以下更改.以下是您的框架中的待办事项列表.
Objective C类中的Swift类用法
#import <YourProjectName/YourProjectName-Swift.h>
在目标c中使用我遵循Apple Mix and Match方法.