Post

Replies

Boosts

Views

Activity

Local xcFrameworks in Swift Packages
In the talk, it was explained how to use a binaryTarget to add a .xcframework from a url, but what about a local path? Take the following Package and file structure, is this the correct way to structure and refer to the .xcFramework? | SamplePackage | - | Package.swift | - | README.swift | - | Sources | - | - | Sample | - | - | - | file.swift | - | - | SampleFramework | - | - | - | framework.xcframework | - | - | Tests | - | - | - | LinuxMain.swift | - | - | - | SampleTexts | - | - | - | - | sampleTests.swift // swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "Sample",     platforms: [         .iOS(.v13),         .macOS(.v10_12)     ],     products: [         // Products define the executables and libraries produced by a package, and make them visible to other packages.         .library(             name: "Sample",             targets: ["Sample", "SampleFramework"]),     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages which this package depends on.         .target( name: "Sample"),         .testTarget(             name: "SampleTests",             dependencies: ["Sample"]),         .binaryTarget(             name: "SampleFramework",             path: "framework.xcframework")     ] ) I am getting the following error(s): invalid custom path 'framework.xcframework' for target 'SampleFramework' target path '/framework.xcframework' is not supported; it should be relative to package root
4
0
8.2k
Jun ’20
How to use a local .xcFramework as a Resource of a Swift Package
I asked this question here incorrectly: https://developer.apple.com/forums/thread/651187?page=1#615966022 What I am actually trying to do is use a local .xcFramework as a Resource inside of a Swift Package without having to distribute it with the package..? Am I supposed to create a binaryTarget as a dependency instead of it being a resource? Im getting the error: "No such module 'SampleFramework' " Example: Say that my SampleFramework has a dependency on sample.xcFramework, how can I add it as a resource to use it in sample.swift Source // Sample.swift // MARK: Import the local xcFramework inside of my package import SampleFramework struct Model { var something: SampleFramework.something } Package file // swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "SamplePackage",     platforms: [         .iOS(.v13) ],     products: [         // Products define the executables and libraries produced by a package, and make them visible to other packages.         .library(             name: "SamplePackage",             targets: ["SamplePackage"]),     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages which this package depends on.         .target(             name: "SamplePackage",             resources: [                 .process("SampleFramework.xcframework") 								// I have also tried .copy()             ]),         .testTarget(             name: "SamplePackageTests",             dependencies: ["SamplePackage"])     ] ) Structure: | SamplePackage | - | Package.swift | - | README.swift | - | Sources | - | - | SamplePackage | - | - | - | sample.swift | - | - | - | SampleFramework.xcframework | - | - | Tests | - | - | - | LinuxMain.swift | - | - | - | SampleTexts | - | - | - | - | sampleTests.swift
3
0
8.3k
Jun ’20
CoreData in Swift Packages
I am having issues loading my model from a Swift Package with the following structure: | Package.swift | Sources | - | SamplePackage | - | - Core | - | - | - SamplePackageDataStack.swift | - | - | - DataModel.xcdatamodeld | - | - | - | - Model.xcdatamodel ( <- is this new? ) As mentioned, I am not required to list the xcdatamodeld as a resource in my Package manifest. When trying to load the model in the main app, I am getting CoreData: error:  Failed to load model named DataModel Code: In my swift Package: public class SamplePackageDataStack: NSObject {     public static let shared = SamplePackageDataStack()     private override init() {}     public lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "DataModel") container.loadPersistentStores(completionHandler: { (storeDescription, error) in             if let error = error as NSError? {                 fatalError("Unresolved error \(error), \(error.userInfo)")             }         })         return container     }()     /// The managed object context associated with the main queue. (read-only)     public var context: NSManagedObjectContext {         return self.persistentContainer.viewContext     }     public func saveContext () {         if context.hasChanges {             do {                 try context.save()             } catch {                 let nserror = error as NSError                 fatalError("Unresolved error \(nserror), \(nserror.userInfo)")             }         }     } } Main App: import SamplePackage class ViewController: UIViewController { override func viewDidLoad() { &#9;&#9;&#9;&#9;&#9;super.viewDidLoad() &#9;var container = SamplePackageDataStack.shared.persistentContainer         print(container) &#9;&#9;} }
4
0
4.9k
Jun ’20