Swift Packages

RSS for tag

Create reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers using Swift Packages.

Posts under Swift Packages tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Beginner Question - Local SPM Folder Structure
Hi there, I am working on an iOS mobile app, with a MVVM architecture and created an SPM folders for my DesignSystem, CoreKit, UnityBridge, and VoicePipeline. I added the packages locally, and dragged them into the project. Is working this way recommended? Or not? Should all the SPM folders I listed above be used this way, or should only some? New to this, unsure what is best. I do plan on sharing my code with other devs to work on. I thought this made sense, but if i did it the other way I was unsure how I would share the packages what is a best practice. Thanks so much!
1
0
57
5d
The new framework AlarmKit is useless
what else can you do with it except for getting the alarm run off? and the alarm even gets dismissed when the user presses any buttons on device even volume buttons. I hope it's better by the time when iOS26 is officially released but I can't prepare for the new iOS update with this useless new framework. does anybody know what new features in this framework are coming up?
0
0
113
1w
SwiftUI vs Flutter for Embedding Unity in an iOS App?
I need help. Looking for devs who’ve integrated Unity into a native iOS app (Swift/SwiftUI) SwiftUI vs Flutter for Embedding Unity in an iOS App? I’m planning an iOS-first app where users interact with a real-time 3D custom avatar with 52 blendshapes powered by Unity, using SALSA LipSync + Emoter for facial animation. The avatar will respond to voice using Whisper → GPT-4 → ElevenLabs. My plan is to embed Unity only for the avatar screen, and build the rest of the app (chat, voice input, onboarding, etc.) natively? Here’s the decision I’m stuck on: Should I stick with SwiftUI, since it gives full access to iOS-native features like ARKit, audio routing, and StoreKit? I only plan to develop for iOS. Has anyone here integrated Unity with Flutter for mobile app successfully? Any pitfalls or major limitations I should know about before going that route? I haven’t started development yet — just want to make sure I choose the right foundation for performance, flexibility, and long-term growth. Any experience would be hugely appreciated!
1
0
165
2w
What is going on with transformable
Hi, I keep trying to use transformable to store an array of strings with SwiftData, and I can see that it is activating the transformer, but it keeps saying that I am still using NSArray instead of NSData. *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "category"; desired type = NSData; given type = Swift.__SwiftDeferredNSArray; value = ( yo, gurt ).' terminating due to uncaught exception of type NSException CoreSimulator 1010.10 - Device: iPhone 16 18.0 (6879535B-3174-4025-AD37-ED06E60291AD) - Runtime: iOS 18.0 (22A3351) - DeviceType: iPhone 16 Message from debugger: killed @Model class MyModel: Identifiable, Equatable { @Attribute(.transformable(by: StringArrayTransformer.self)) var category: [String]? @Attribute(.transformable(by: StringArrayTransformer.self)) var amenities: [String]? var image: String? var parentChunck: MyModelDataChunk_V1? init(category: [String]?, amenities: [String]?) { self.category = category self.amenities = amenities } } class StringArrayTransformer: ValueTransformer { override func transformedValue(_ value: Any?) -> Any? { print(value) guard let array = value as? [String] else { return nil } let data = try? JSONSerialization.data(withJSONObject: array, options: []) print(data) return data } override func reverseTransformedValue(_ value: Any?) -> Any? { guard let data = value as? Data else { return nil } let string = (try? JSONSerialization.jsonObject(with: data, options: [])) as? [String] print(string) return string } override class func transformedValueClass() -> AnyClass { return NSData.self } override class func allowsReverseTransformation() -> Bool { return true } static func register() { print("regitsering") ValueTransformer.setValueTransformer(StringArrayTransformer(), forName: .stringArrayTransformerName) } } extension NSValueTransformerName { static let stringArrayTransformerName = NSValueTransformerName("StringArrayTransformer") }
1
0
83
2w
Avoiding Plugin Execution in a Linked Swift Package During Top-Level Package Builds
I am working on an iOS project using Xcode 16.0 that leverages multiple Swift packages. Among these, I have a Shared Package that contains reusable code and is linked to several top-level feature packages (e.g., VideoPlayer, VideoEditor, etc.). The Shared Package includes a Swift Package Manager plugin for linting code standards, which is designed to execute during its own build process. However, when building a top-level package (e.g., VideoPlayer), the Shared Package is also built as part of the dependency graph. During this process, the linting plugin in the Shared Package is executed unnecessarily, even though the intent is to only build the Shared Package's code. This behavior results in a significant increase in build times for the top-level packages, as the linting plugin is executed every time the Shared Package is built indirectly. Key Details: Xcode Version: 16.0 Swift Package Manager: Used for dependency management. Issue: The linting plugin in the Shared Package executes during the build of top-level packages, increasing build times. Expected Behaviour: The plugin should only execute when the Shared Package is built directly, not when it is built as a dependency of a top-level package. I would like to know if there is a way to configure the Shared Package or the Swift Package Manager to prevent the plugin from executing when the Shared Package is built as a dependency of a top-level package, while still allowing the plugin to run when the Shared Package is built directly. Any guidance, configuration tips, or best practices to address this issue would be greatly appreciated.
0
0
38
2w
HotKey support for sandboxed apps
App design: macos, Xcode 16.4, Sequioa 15.5, it is sandboxed Uses: Pods->HotKey for a global hotkey which xcode says "binary compatibility can't be guaranteed" This app is on the Apple Store and supposedly apps on the Apple Store can't use global hotkeys. Someone internally, installed it from the store and the global hotkey works just fine. I'm concerned for two potential problems; I need to find a hotkey library or code that is known to work with a sandbox'd Apple Store app. Why is it working now when everything I have read says it shouldn't.
0
0
90
3w
Access resource in swift package from xcframework
I have an iOS app that includes a local Swift package. This Swift package contains some .plist files added as resources. The package also depends on an XCFramework. I want to read these .plist files from within the XCFramework. What I’d like to know is: Is this a common or recommended approach—having resources in a Swift package and accessing them from an XCFramework? Previously, I had the .plist files added directly to the main app target, and accessing them from the XCFramework felt straightforward. With the new setup, I’m trying to determine whether this method (placing resources in a Swift package and accessing them from an XCFramework) is considered good practice. For context: I am currently able to read the .plist files from the XCFramework by passing Bundle.module through one of the APIs exposed by the XCFramework.
3
1
111
3w
Projecting a Cube with a Number in ARKit
I'm a novice in RealityKit and ARKit. I'm using ARKit in SwiftUI to show a cube with a number as shown below. import SwiftUI import RealityKit import ARKit struct ContentView : View { var body: some View { return ARViewContainer() } } #Preview { ContentView() } struct ARViewContainer: UIViewRepresentable { typealias UIViewType = ARView func makeUIView(context: UIViewRepresentableContext<ARViewContainer>) -> ARView { let arView = ARView(frame: .zero, cameraMode: .ar, automaticallyConfigureSession: true) arView.enableTapGesture() return arView } func updateUIView(_ uiView: ARView, context: UIViewRepresentableContext<ARViewContainer>) { } } extension ARView { func enableTapGesture() { let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:))) self.addGestureRecognizer(tapGestureRecognizer) } @objc func handleTap(recognizer: UITapGestureRecognizer) { let tapLocation = recognizer.location(in: self) // print("Tap location: \(tapLocation)") guard let rayResult = self.ray(through: tapLocation) else { return } let results = self.raycast(from: tapLocation, allowing: .estimatedPlane, alignment: .any) if let firstResult = results.first { let position = simd_make_float3(firstResult.worldTransform.columns.3) placeObject(at: position) } } func placeObject(at position: SIMD3<Float>) { let mesh = MeshResource.generateBox(size: 0.3) let material = SimpleMaterial(color: UIColor.systemRed, roughness: 0.3, isMetallic: true) let modelEntity = ModelEntity(mesh: mesh, materials: [material]) var unlitMaterial = UnlitMaterial() if let textureResource = generateTextResource(text: "1", textColor: UIColor.white) { unlitMaterial.color = .init(tint: .white, texture: .init(textureResource)) modelEntity.model?.materials = [unlitMaterial] let id = UUID().uuidString modelEntity.name = id modelEntity.transform.scale = [0.3, 0.1, 0.3] modelEntity.generateCollisionShapes(recursive: true) let anchorEntity = AnchorEntity(world: position) anchorEntity.addChild(modelEntity) self.scene.addAnchor(anchorEntity) } } func generateTextResource(text: String, textColor: UIColor) -> TextureResource? { if let image = text.image(withAttributes: [NSAttributedString.Key.foregroundColor: textColor], size: CGSize(width: 18, height: 18)), let cgImage = image.cgImage { let textureResource = try? TextureResource(image: cgImage, options: TextureResource.CreateOptions.init(semantic: nil)) return textureResource } return nil } } I tap the floor and get a cube with '1' as shown below. The background color of the cube is black, I guess. Where does this color come from and how can I change it into, say, red? Thanks.
4
0
78
2w
No such module 'JournalingSuggestions'
I followed this tutorial to add JournalingSuggestions API, but it keeps showing me No such module 'JournalingSuggestions'. How can I fix this? import SwiftUI import JournalingSuggestions struct ContentView: View { @State var suggestionTitle: String? = nil var body: some View { VStack { JournalingSuggestionsPicker { Text("Select Journaling Suggestion") } onCompletion: { suggestion in suggestionTitle = suggestion.title } Text(suggestionTitle ?? "") } .padding() } } #Preview { ContentView() }
2
0
39
3w
Compiling Swift Package with Dependency on Build Tool Plugin Fails in Xcode 26
Hi, in our Xcode project we have a Tooling package, which defines build tool plugins for generating compile time safe constants for our localization strings as well as assets using swiftgen. This is working very well in Xcode 16, but fails in Xcode 26 beta 1 and beta 2 as well. The failure is specifically: unsupported configuration: the aggregate target 'Localization' has package dependencies, but targets that build for different platforms depend on it. I've reduced this to a minimal sample project, which you can find here.. To reproduce: Open the Repro workspace, that is attached in Xcode. Try to build TestyPackage. You'll see the error. I've filed this bug during WWDC week, but no feedback yet and no solution in Xcode 26 beta 2. Here's the feedback number, in case you have this too and want to file a duplicate: FB17934050. Does anyone else have this issue and perhaps a solution?
2
3
118
2w
Apple Watch no longer connects reliably in Xcode
Hi all, I'm developing a standalone SwiftUI watchOS app (no iOS host or extension), targeting watchOS 11.5, and running into persistent connection issues with Xcode. Xcode rarely detects my Apple Watch (Series 7, watchOS 11.5) Sometimes it appears nested under the iPhone; most of the time, it doesn’t Errors include: "OS version is lower than the deployment target" (both are 11.5) "Unable to install... device not supported" "Connection error 4000", "Tunnel timeout error 1001" "Ensure Wi-Fi is enabled on both machines" (Wi-Fi is on and on the same network) Once in a while, the app does install, but mostly I’m blocked. What I’ve Tried Verified pairing and trust Cleaned builds, nuked Derived Data and caches Reset iPhone privacy settings Removed and re-added my Apple ID Used xcrun xctrace list devices (watch inconsistently appears) Despite this, the app only installs about 5% of the time. Testing (or even running) on real hardware is nearly impossible, and has become incredibly frustrating for me. Any help or insights would be much appreciated.
0
0
32
3w
How can you communicate that a .xcframework is a dependency OF the swift package inside Swift package definition?
I am sort of trying to do the opposite of what others are doing. I have a target called CopyFramework that creates a CopyFramework.framework within my main xcproj file. I set up this target because a specific framework (we can call it Tools.xcframework) is distributed as a binary. That framework file lives within the code. Tools.xcframework is structured like so Tools.xcframework (Coding/testBuild/DynamicToolFrameworks/Tools.xcframework) info.plist ios-arm64/ Tools.xcframework/ Tools (executable file) Tools.bundle Headers/ Info.plist Modules/ Tools.swiftmodule/ arm64-apple-ios.abi.json arm64-apple-ios.private.swiftinterface arm64-apple-ios.swiftdoc arm64-apple-ios.swiftinterface module.modulemap module.private.modulemap PrivateHeaders/ ios-arm64_x86_64-simulator/ When the CopyFramework target is run xcode does a few steps which copy the correct version of this framework to derived data. Process Tools.xcframework (iOS) Coding/testBuild/DynamicToolFrameworks/Tools.xcframework /Library/Developer/Xcode/DerivedData/testBuild-sha/Build/Products/Debug-iphoneos/Tools.framework ios cd /Users/calebkierum/Coding/testBuild builtin-process-xcframework --xcframework Coding/testBuild/DynamicToolFrameworks/Tools.xcframework --platform ios --target-path Library/Developer/Xcode/DerivedData/testBuild-sha/Build/Products/Debug-iphoneos Meaning essentially that the Tools.xcframework for the proper platform is taken from Tools.xcframework/ios-arm64 and copied to Library/Developer/Xcode/DerivedData/testBuild-sha/Build/Products/Debug-iphoneos/Tools.xcframework I am writing a Swift Package that needs to be able to reference the correct Tools.xcframework. I have set it up like so: let package = Package( name: "CoreObjC", platforms: [.iOS(.v17), .macCatalyst(.v17)], products: [ .library(name: "CoreObjC", targets: ["CoreObjC"]), ], dependencies: [ // Does something to here ??? //.package(path: "../testBuild") ], targets: [ .target( name: "CoreObjC", dependencies: [ // Here I would like to be referencing the CopyFramework.framework target within my buildTest.xcproj file .product(name: "CopyFramework", package: /*??? its not in a swift package its a part of an xcproj file*/) ], path: "CoreObjC", publicHeadersPath: "Headers", linkerSettings: [ .linkedFramework("Tools", .when(platforms: [.iOS])), .linkedLibrary("c++") ] ), ], cxxLanguageStandard: CXXLanguageStandard.gnucxx14 ) Now obviously this does not work. I do not know how to communicate to the Package.swift file that the binary dependency is a framework target within my xcproj file. If I do run the target CopyFramework followed by building CoreObjC it works though (so long as you comment out the bits trying to reference CopyFramework). Running the CopyFramework target processes the Tools.xcframework and copies the proper xcframework sub folder to Derived data and the Swift Package build system seems to be able to see it. Is there a way I can get rid of this manual step? Make it so that when I build the CoreObjC target (swift package) that either CopyFramework is run or some other process is run to get the proper xcframework out of Coding/testBuild/DynamicToolFrameworks/Tools.xcframework and into DerivedData? Is it even theoretically possible to have a Swift Package reference a target in a normal xcproj file?
0
0
50
Jun ’25
Binaries nested in frameworks - possible or not with iOS?
I'd like to determine, definitively, if nesting of "binaries" within other "binaries" is possible with iOS. I put binaries in quotes because I've read documentation/forum posts stating things like nested frameworks isn't supported in iOS. A framework is a binary isn't it, or contains one. So does a statement such as that apply specifically and only to nested frameworks, or does it also apple to other scenarios - such as a SPM binary integrated into a framework? Here's the specific scenario I'm seeking clarity on - suppose an SDK providing an API/functionality is built as an .xcframework and that SDK contains dependencies on two other components (Firebase, AlmoFire, RealmSwift, CocoaLumberjack, whatever etc.). Lets say the SDK has two dependencies X and Y and it integrates them via SPM. Q1: If there is an app A which integrates the SDK, and A doesn't use X and Y itself, then can X and Y be embedded within the SDK and thus opague to A? Is this possible in iOS? Q2: If A integrates the SDK as above, but additionally, it itself uses X and Y independently of the SDK, then is this situation possible in iOS? Presumably in Q1 the SDK needs to embed X and Y into the framework? While presumably in Q2 it should not - because the app will be and hence that would lead to duplicate symbols and potential undefined behaviour (and therefore X and Y's SPM package spec needs to specify dynamic?) I've been trying to get a clear picture of this for literally weeks and weeks, without reaching a clear conclusion. So some definitive answer would be very much appreciated.
1
0
67
Jun ’25
Module not found when using inheritance
PLATFORM AND VERSION Development environment: Xcode 16.4 (16F6), macOS 15.5 (24F74) Run-time configuration: iOS 18.3.1 DESCRIPTION OF PROBLEM I cannot build my app due to a module not found error when I'm importing Sample-Swift.h header to an ObjectiveC file. I need to use Swift code to ObjectiveC file with Swift code using an external XCFramework. It seems to be related to a mix with ObjectiveC and Swift code when Swift code uses class inheritance from FZWorkoutKit class. With a full Swift project, no issue. STEPS TO REPRODUCE Project https://fizzup.s3.amazonaws.com/files/public/Sample-WK.zip Open the provided project and try to build it. The issue occurs. In MyObject.m file, if you comment the first import (Sample-Swift.h), no issue occurs but I cannot use my Swift code (MyFile class). Uncomment the line commented in step 1. Go to MyFile.swift and change class inheritance from GoModeController (from FZWorkoutKit framework) to UIView (from UIKit). No issue occurs.
0
0
46
Jun ’25