gpt4 book ai didi

Objective-C 代码 Swift-framework-internal

转载 作者:搜寻专家 更新时间:2023-11-01 06:36:14 25 4
gpt4 key购买 nike

我有一个 Swift 框架的以下结构:

FrameworkA
├── FrameworkA.swift
└── Objective-C
├── ClassA.h
└── ClassA.m

不幸的是,我无法访问 FrameworkA.swift 中的 ClassA;错误是:

Use of unresolved identifier 'ClassA'

ClassA 应 protected /框架内部。

我做错了什么?

最佳答案

根据 Apple Docs

Importing Objective-C into Swift

To import a set of Objective-C files in the same framework target asyour Swift code, you’ll need to import those files into theObjective-C umbrella header for the framework.

To import Objective-C code into Swift from the same framework

Under Build Settings, in Packaging, make sure the Defines Modulesetting for that framework target is set to “Yes”. In your umbrellaheader file, import every Objective-C header you want to expose toSwift. For example:

#import <XYZ/XYZCustomCell.h>
#import <XYZ/XYZCustomView.h>
#import <XYZ/XYZCustomViewController.h>

因此,从官方角度来看,似乎没有办法在不公开的情况下在 Swift 文件中看到 Objective-C 类。 ☹️

关于Objective-C 代码 Swift-framework-internal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41303716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com