获取错误Receiver for class message是一个前向声明 [英] Getting Error Receiver for class message is a forward declaration

查看:2169
本文介绍了获取错误Receiver for class message是一个前向声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建自己的框架,我添加了客观的c文件,并且工作正常后我需要在添加swift文件后添加一些swift文件xcode没有给我选择auto 创建桥接然后我跟着

解决方案

最后我得到了解决方案。我做了以下更改。以下是您的框架中的列表。



Objective C类中的Swift类使用




  • 在Swift中的类名前使用Open Keyword

  • 在打开Swift类的关键字之前使用@objc关键字

  • 在Umbrella文件中导入目标c类的所有标题
    YourProject.h那些正在使用Swift类。

  • 使用 #import< YourProjectName / YourProjectName-目标
    c中的Swift.h>



我遵循Apple Mix and Match方法。


I'm working on creating my own framework, I added objective c files and its working fine after that I needed to add some swift file after adding swift file xcode is not giving me option of auto Creating Bridging then I followed Mix and Match approach. I followed everything which I thing I understand.

I want to access swift file into Objective c but I'm getting error of forward declaration so Here is sample code I attached, kindly guide me where I'm doing wrong.

TestObjectCFile.h

#import <Foundation/Foundation.h>
@class TestSwiftFile;
@interface TestObjCFile : NSObject


@end

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

TestSwiftFile.swift

import Foundation

And the error occur on TestObjectCFile.m following line.

TestSwiftFile * testSwiftFile = [[TestSwiftFile alloc] init];

as show attached picture.

解决方案

Finally I got solution. I did following changes. Here below is to do list in your Framework.

Swift classes usage in Objective C classes

  • Use Open Keyword before class name in Swift
  • Use @objc Keyword before Open Keyword of Swift class
  • Import all header of objective c classes in Umbrella file YourProject.h those are consuming Swift Classes.
  • Use #import <YourProjectName/YourProjectName-Swift.h> in Objective c

I followed Apple Mix and Match approach.

这篇关于获取错误Receiver for class message是一个前向声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆