简体   繁体   English

如果依赖于仅应用程序的代码,可以在应用程序及其扩展名之间共享.swift文件吗

[英]Can you share a .swift file between an app and its extension if it relies on app-only code

I have the following set of files in my project: 我的项目中有以下文件集:

文件结构图

The IAPHelper class uses the objective-c through a bridging header. IAPHelper类通过桥接标头使用Objective-C。 I was wondering if I could use the IAPHelper class in both my app and its app extension like this: 我想知道是否可以在我的应用及其应用扩展中使用IAPHelper类,如下所示:

(Setting IAPHelper's target membership) (设置IAPHelper的目标成员)

IAPHelper_Membership

Without making KeychainWrapper being a member of both classes. 无需让KeychainWrapper成为这两个类的成员。

No it does not seem to work. 不,它似乎不起作用。

I made TestClassOne 我做了TestClassOne

import Foundation

class TestClassOne {
static internal func addOneOne() -> Int {
    return 2;
}


}

TestClassOne is only part of one target. TestClassOne只是一个目标的一部分。

I made TestClassTwo 我做了TestClassTwo

import Foundation

class TestClassTwo {
internal static func callTestClassOne() -> Int {

    let i = TestClassOne.addOneOne()
    return i


}

}

TestClassTwo belonged too both targets. TestClassTwo属于两个目标。 I would keep on getting the error TestClassOne not recognized when the TestClassOne file was set to only one target but once I set the TestClassOne file to both targets that error stopped appearing. 我会不断收到错误TestClassOne时无法识别TestClassOne文件设置为只有一个目标,但一旦我设定TestClassOne文件的错误不再出现两个目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于在共享扩展和iOS应用之间共享文件路径/文件的代码 - Code to share file path/file between a share extension and iOS app 在iOS App及其扩展程序之间共享情节提要 - Share Storyboard between iOS App and its Extension 在React Native应用和Swift Share Extension之间共享UserDefaults - Share UserDefaults between React Native app and Swift Share Extension iOS使用Alamofire快速在应用程序和共享扩展之间共享Cookie - iOS swift using alamofire to share cookie between app and share extension 在Swift中的应用和今日扩展之间共享核心数据数据库 - Share Core Data database between app and today extension in Swift (iOS Swift)在应用程序和Today Extension之间共享EKEventStore和访问 - (iOS Swift) Share EKEventStore and access between app and Today Extension 使用钥匙串在 iOS 扩展程序及其包含的应用程序之间共享? - Share between an iOS extension and its containing app with the keychain? 在应用程序和扩展程序之间共享 NSPersistentCloudKitContainer - share NSPersistentCloudKitContainer between app and extension 如何使用仅应用程序访问权限将特定于应用程序的数据写入设备的文件存储 - How to write app-specific data to device's file storage with app-only access permissions 主应用程序和共享扩展名之间的iOS共享.h文件 - iOS Sharing .h file between main app and share extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM