![](/img/trans.png)
[英]Objective-C : “receiver FBSDKAccessToken for class message is a forward declaration”
[英]Receiver '**' for class message is a forward declaration Error. Swift Static Library use in Objective-C
我正在嘗試制作一個 Swift Static 庫並將其應用於 Swift 和目標項目。
import Foundation
@objc open class Library001_Test: NSObject {
public override init(){}
@objc public func testPrint() {
print("My Name is Andi")
}
@objc public func getUUID(userName: String) -> String {
let uuid = UUID().uuidString
return "\(userName)'s UUID : \(uuid)"
}
}
我使用 Swift 編寫了這樣的代碼。
在 Edit Scheme 菜單中,我將 Build Configuration 更改為 Release 並繼續運行。 結果,創建了“libLibrary001.a”文件和“Library001.swiftmodule”文件夾。
但是問題是一個Objective-C項目。
我將這兩個工件放入我的項目並檢查:
[一般 - 框架、庫。 and Embedded Content]庫是否被識別
庫是否在 [Build Phases - Link Binary With Libraries] 中被識別
勾選【Build Settings - Library Search Paths】地址
定義模塊 - 是
然后我輸入“@class Library001_Test;” 在 ViewController.h 中
#import <UIKit/UIKit.h>
@class Library001_Test;
@interface ViewController : UIViewController
@end
在 ViewController.m 中,'#import "ProductName-Swift.h" 和創建的 Class 被加載。
#import "ViewController.h"
#import "SwiftInObjectiveC-Swift.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
Library001_Test *test = [[Library001_Test alloc] init];
}
@end
錯誤:class 消息的接收者“Library001_Test”是前向聲明
錯誤:例如消息的接收者類型“Library001_Test”是前向聲明
執行此操作時發生錯誤。 我已經嘗試了我在 inte.net 上找到的所有方法,我想知道問題出在哪里。
是代碼的問題嗎? 是我沒設置好嗎??
項目中創建的Swift文件在Objective-C中導入良好...為什么.a文件不能這樣工作?
我的問題是“(ProductName)-Swift.h”
看看Objective-C中Swift代碼是怎么用的,很多文章都說import (ProductName)-Swift.h。 所以我只添加了我要申請的項目header,但是我還需要添加從庫中制作的產品header。
我的問題很簡單,但我花了很長時間才弄明白。 Swift static library not found 'Class' and 'func' 報錯。 我的解決方法是使用我創建的庫的 (LibraryProductName)-Swift.h 解決的,而不是您正在處理的項目的 (ProductName)-Swift.h。
如果您參考下面的地址,您可以提前防止發生的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.