Hi, first time question.
I have a game app that I am trying to include google ads on:
import GoogleMobileAds
I have the following bit of code:
init() {
GADMobileAds.sharedInstance().start(completionHandler: { _ in
print("✅ AdMob started successfully")
})
}
That is throwing the following error:
OliviasGameApp.swift:9:22 Cannot call value of non-function type 'MobileAds'
I have gone through countless troubleshooting, including transitioning to Pods. Is there any help on what I can do to resolve this issue?
Swift Packages
RSS for tagCreate 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
This browser extension is a doc reading enhancer for the Apple Developer website.
It supports i18n translation, hover link previews, and bilingual display.
Currently, it supports four languages: ja-JP, ko-KR, zh-CN, and zh-TW.
It works with Swift/SwiftUI/Foundation modules now, and it's expected to support Swift Test, Swift Charts, UIKit, Swift Playground, and XCode modules by the end of this month.
For more info, check out: https://appledocs.dev.
You can also visit https://appledocs.dev/progress to see translation progress and vote.
Note: It's only works on Chrome、Edge(In review)、Firefox(In review)
Screenshot:
Topic:
Developer Tools & Services
SubTopic:
General
Tags:
Swift Packages
Developer Tools
Safari Extensions
Apple Intelligence
我想在我的 Mac OS 项目 (Swift UI) 中添加一个 Package dependency Package,但我只能添加一个 Package Collection,我不能只添加一个单独的包依赖包,我想添加 mysql kit 以使我的项目链接到 Mysql 数据库
An internal error occurs when executing the xcodebuild -list command targeting a Swift Package. This behavior is new in Xcode 16.3 and was not present in the previous version, Xcode 16.2.
cd ~/Developer
mkdir Playground
cd Playground
swift package init
xcodebuild -list
Command line invocation:
/Applications/Xcode-16.3.0.app/Contents/Developer/usr/bin/xcodebuild -list
Resolve Package Graph
** INTERNAL ERROR: Unable to load workspace '/Users/treastrain/Developer/Playground' **
Uncaught Exception: -[Swift.__SwiftDeferredNSArray intersectsSet:]: unrecognized selector sent to instance 0x600001aab5e0
Stack:
0 __exceptionPreprocess (in CoreFoundation)
1 objc_exception_throw (in libobjc.A.dylib)
2 -[NSObject(NSObject) __retain_OA] (in CoreFoundation)
3 ___forwarding___ (in CoreFoundation)
4 _CF_forwarding_prep_0 (in CoreFoundation)
5 -[DVTCoreDevice(DVTCoreDeviceIDE) deviceSupportsBuildable:buildParameters:error:] (in IDEFoundation)
6 -[DVTCoreDevice(DVTCoreDeviceIDE) supportedArchitecturesForBuildableContext:buildParameters:error:] (in IDEFoundation)
7 _IDERunDestinationsForBuildableUsingDeviceWithBuildParameters (in IDEFoundation)
8 -[IDERunDestinationManager runDestinationsForScheme:schemeCommands:executionEnvironment:eligibleOnly:genericOnly:architectureVisibility:] (in IDEFoundation)
9 IDESchemeDetermineAvailableRunDestinations (in IDEFoundation)
10 -[IDEScheme _actuallyInvalidateAvailableRunDestinations] (in IDEFoundation)
11 addSchemeAndMakeActiveIfNecessary #1 (result:error:) in IDESwiftPackage.generateScheme(with:buildable:additionalBuildables:unsetRunnable:makeActive:orderHint:) (in IDESwiftPackageCore)
12 IDESwiftPackage.generateScheme(with:buildable:additionalBuildables:unsetRunnable:makeActive:orderHint:) (in IDESwiftPackageCore)
13 IDESwiftPackage.generateSchemes(_:isRootPackage:) (in IDESwiftPackageCore)
14 IDESwiftPackage.update(from:graphHasErrors:delegate:) (in IDESwiftPackageCore)
15 specialized IDESPMWorkspaceDelegate.rootPackagesDidUpdate(packages:graphHasErrors:modelGraphSynchronizerToken:) (in IDESwiftPackageCore)
16 closure #1 in IDESPMWorkspaceDelegate.packageGraphDidFinishAction(_:duration:result:) (in IDESwiftPackageCore)
17 partial apply for closure #1 in IDESPMWorkspaceDelegate.disableWorkspaceContentSynchronization(during:) (in IDESwiftPackageCore)
18 <deduplicated_symbol> (in DVTFoundation)
19 <deduplicated_symbol> (in DVTFoundation)
20 thunk for @escaping @callee_guaranteed () -> () (in DVTFoundation)
21 __58-[DVTModelObjectGraph performBlockCoalescingModelChanges:]_block_invoke (in DVTFoundation)
22 -[DVTModelGraphTransactionScope performTransaction:] (in DVTFoundation)
23 -[DVTModelObjectGraph performBlockCoalescingModelChanges:] (in DVTFoundation)
24 DVTModelObjectGraph.performBlockCoalescingModelChanges<A>(_:) (in DVTFoundation)
25 IDESPMWorkspaceDelegate.disableWorkspaceContentSynchronization(during:) (in IDESwiftPackageCore)
26 IDESPMWorkspaceDelegate.packageGraphDidFinishAction(_:duration:result:) (in IDESwiftPackageCore)
27 <deduplicated_symbol> (in IDESwiftPackageCore)
28 SPMWorkspace.packageGraphActionFinished(_:) (in SwiftPM)
29 closure #2 in closure #3 in SPMWorkspace.processPackageGraphActionsInBackgroundIfNeeded(canProcessPackageGraphActions:) (in SwiftPM)
30 <deduplicated_symbol> (in SwiftPM)
31 <deduplicated_symbol> (in SwiftPM)
32 <deduplicated_symbol> (in SwiftPM)
33 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) (in libswift_Concurrency.dylib)
zsh: abort xcodebuild -list
Environments:
% xcodebuild -version
Xcode 16.3
Build version 16E140
% swift --version
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Hey iOS Dev's,
I’m currently working on a Swift Package Manager (SPM) for WireGuard, originally developed by a previous team member. It was working fine in Xcode 15.2, but after upgrading to Xcode 16 and Swift 6, I need to update the SPM to ensure compatibility with my base projects and other projects relying on it.
With Apple making Xcode 16 mandatory for app submissions starting April 24, this has become an urgent issue. I’ve searched extensively but haven’t found a working solution yet.
Has anyone faced similar challenges with Swift 6 migration and SPM updates? Any insights, best practices, or debugging tips would be greatly appreciated!
Let’s connect and collaborate—I’d love to discuss possible solutions! 😊
#iOSDevelopment #Swift6 #Xcode16 #SPM #WireGuard #iOS #Swift #SoftwareEngineering #AppStore
I want to statically link xcframework as binaryTarget in Swift Package, but it is copied into the product as dynamic when the Xcode build. How to use xcframework in SwiftPackage and statically link it into iOS product?
The Package.swift content and the project are:
The WebP.xcframework is static:
The Xcode Build Product's WebP.framework is dynamic:
The flags like #if DEBUG ... endif are dependent on the Active Compilation Conditions. So if they say DEBUG the enclosed code block will be executed, otherwise not.
Now I have the phenomenon that a #DEBUG block in a Package does not evaluate these conditions. It rather depends on the name of the configuration used to build.
So if I build my app with Active Compilation Condition set to DEBUG, but the configuration name is something like App-Release, the DEBUG block in my Package is not added/executed. The ones which are directly in the project are added.
Vice versa if the Compilation Condition say RELEASE but the configuration is called App-Debug the blocks in the Package are added to the compilation, but the ones in the project itself are not
It suffices that the config name contains the word Debug for this to happen. E.g. the configuration App-Release-Debug (I know that this would be stupid, but it is for demonstrating purposes) will cause the Packages to include the DEBUG blocks.
This happens no matter what you set in the Build Settings of the project and/or target.
The Packages are added via GitHub/GitLab Source Control with SPM.
Any ideas why this behaves like it does? It doesn't seem like it should...
So I will summary an issue one of our clients has asked us on GitHub:
https://github.com/pendo-io/pendo-mobile-sdk/issues/233
Project that is a custom framework that uses different SPM packages (one of them is Binary package), we have our main logic inside that framework and we have different targets that use this framework, everything works on the simulator, but running the app on the actual device provokes a crash saying "Binary framework was not found". We have like 20 other SPM packages that work fine, this is the first one we have an issue with.
Please note I understand that SPM will not copy paste the Binary for the magic framework as it does for the apps so I suggested to embed it manually.
So my question is what the best(easy) way to do it.
Please refer to the following issue for more details:
https://github.com/pendo-io/pendo-mobile-sdk/issues/233
I've used SPM to install some dependencies, however for one of them, CocoaLumberjackSwift the Embed section is blank and attempting to click in it doesn't brink up any dropdown menuetc.
Why is that, how can I change it or check what its set to if its blank?
(Code 16.2)
Since upgrading from Xcode 15 to 16, we have been experiencing a build error during compilation. Building on Xcode 15 still works with no issues. The error happens only on the first build after a clean. Subsequent builds succeed. This is an issue because our CI process archives the project from a clean slate, and this causes it to fail every time. I will attempt to describe the issue and include information I believe is relevant in this document.
The error occurs on this import line within an Objective-C file during the Scan Dependencies step of compiling. This line imports our custom Objective-C to Swift bridging header file - "Swift2Objc.h".
Our custom Objective-C to Swift bridging header file is simply wrapping the project’s auto-generated Objective-C to Swift bridging header file - "KWISwift.h".
The error is specific to the import of the OfflineServices Swift Package.
Specifically, the OfflineServices-Swift.h file - the Swift Package’s auto-generated Objective-C to Swift bridging file.
Module JRE not found - the exact error (Also included as text on the bottom of the post)
JRE is a third-party library provided to us as an xcframework. It is placed directly into our Swift Package as a binary target.
The xcframework itself is composed of .a file and a Headers folder which includes header files and a module.modulemap.
The module.modulemap file looks like this.
If I install RealmSwift into an ios app using SPM, I have no problems.
However if I install it into an ios framework, then when building there is this error:
error: missing required modules: 'Realm.Private', 'Realm', 'Realm.Swift'
I have discovered that if I change the import statement from:
import RealmSwift
to
private import RealmSwift
then doing that makes this build error goes away (but doing that isn't a feasible workaround as I would like to publicly export classes stored in Realm from the framework).
There's no point in posting issues with Realm on their support board as its being deprecated and its tumble weeds on their forum.
But I would be very interested in hearing from the Apple expects explanation or speculation on:
why is importing the same framework via SPM into a framework xcode project resulting in different behavior then when importing it into an app?
why would changing import to private import make the build error go away?
TIA
I’ve been working on a Catalyst version of my iOS apps.
Finally everything is working apart from the custom intents the user user to configure the widgets.
The config UI loads:
And changing settings at this level works.
But it can’t load the options for the other settings:
“No options were provided for this parameter”
I see this crash in the intent:
Termination Reason: Namespace DYLD, Code 1 Library missing
Library not loaded: @rpath/CocoaLumberjack.framework/Versions/A/CocoaLumberjack
Referenced from: <E1BF4CC5-4181-3272-828C-86B1CD1A66BF> /Applications/my.app/Contents/PlugIns/Intents.appex/Contents/MacOS/Intents
Reason: , (security policy does not allow @ path expansion)
(terminated at launch; ignore backtrace)
I have added the Hardened Runtime Capability to the Main App Target, the Widget Target and the Intents Target. I also allowed “Disable Library Validation” just in case.
What am I missing?
I have an app that run Monte Carlo simulations. I run thousands of simulations in the app and a simulation runs can take on the order of 30 seconds to a minute to complete. I would like to have a progress view that tracks the number of simulation runs. How can I implement this in swiftui?
DocC supports treating build warnings as errors using the --warnings-as-errors flag. Is there a way to pass this flag to xcodebuild docbuild command or do I need to use xcrun docc convert after generating the symbol graph?
Hi.
I have a xcframework that has a dependency on 'RxSwift' and 'RxCocoa'. I deployed it using SPM by embedding it in a Swift Package.
However when I import swift package into another project, I keep getting the following error:
"Missing required module 'RxCocoaRuntime"
How can I fix this?
Below are the steps to reproduce the error.
Steps
Create Xcode proejct, make a dependency on 'RxSwift' and 'RxCocoa' (no matter doing it through tuist or cocoapods)
Create XCFramework from that proejct. (I used commands below)
xcodebuild archive \
-workspace SimpleFramework.xcworkspace \
-scheme "SimpleFramework" \
-destination "generic/platform=iOS" \
-archivePath "./SimpleFramework-iphoneos.xcarchive" \
-sdk iphoneos \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild archive \
-workspace SimpleFramework.xcworkspace \
-scheme "SimpleFramework" \
-archivePath "./SimpleFramework-iphonesimulator.xcarchive" \
-sdk "iphonesimulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework "./SimpleFramework-iphoneos.xcarchive/Products/Library/Frameworks/SimpleFramework.framework" \
-framework "./SimpleFramework-iphonesimulator.xcarchive/Products/Library/Frameworks/SimpleFramework.framework" \
-output "./SimpleFramework.xcframework"
Embed in Swift Package, and deploy.
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "SimplePackage",
platforms: [.iOS(.v16)],
products: [
.library(
name: "SimplePackage",
targets: ["SimplePackage"]),
],
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift", from: "6.8.0")
],
targets: [
.binaryTarget(
name: "SimpleFramework",
path: "Sources/SimpleFramework.xcframework"
),
.target(
name: "SimplePackage",
dependencies: [
"SimpleFramework",
"RxSwift",
.product(name: "RxCocoa", package: "RxSwift")
]
)
]
)
Download Swift Package in another project and import module.
I resolved this by removing dependencies from the Swift Package, downloading package in another project, and fetching dependencies by cocoapods.
Thist works, but I don't want to use another dependency manager while using SPM.
Development Environment
CPU : Apple M4 Max
MacOS : Sequoia 15.3
Xcode : 16.2
I'm trying to improve my build time on macOS by not building for x86_64. I've got the following settings:
This gets Xcode not to build x86_64 for my app, but not all the package dependencies.
I've updated most of the packages to swift-tools-version: 6.0 but FlatBuffers is still on 5.8 and .macOS(.v10_14). GPT claims:
If your deployment target is set to macOS 10.15 or earlier, Xcode may force x86_64 support for compatibility reasons.
But Xcode is building x86_64 for ALL my packages, even the ones that don't depend on FlatBuffers.
When I open a package in Xcode that depends on FlatBuffers, then it builds arm only, so that may be a red herring.
Not sure what else to try.
I had several library projects that were working in Swift Playgrounds < 4.6 but I get several duplicate compilation errors and previews will not build in Swift Playgrounds > 4.6. Does anyone know how to fix this issue?
Example project:
This project builds and runs fine under Swift Playgrounds 4.5.1 however it will not run complaining multiple commands produce generated output files under Swift Playgrounds 4.6.1, 4.6.2, and 4.6.3.
https://github.com/kudit/Compatibility
Download this repository and add the extension ".swiftpm" to the folder and double click to open in Swift Playgrounds. If running on earlier Swift Playgrounds you can see there are no errors and previews work great (on both macOS and iPadOS versions of Swift Playgrounds 4.5.x). However, on Swift Playgrounds 4.6.x, previews will not display.
Are embedded libraries not support anymore? This would be very disappointing.
I posted this as a Feedback weeks ago with no response: FB16509699
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags:
Swift Packages
Swift Playground
Playground Support
I'm simply trying to use a proxy to route a http request in Swift. I've tried using a URLSession Delegate but that results in the same issue with the iOS menu.
proxy format: host:port:username:password
When I run the code below I am prompted with a menu to add credentials for the proxy. I closed this menu inside my app and tried the function below again and it worked without giving me the menu a second time. However even though the function works without throwing any errors, it does NOT use the proxies to route the request.
I've spent days on this and the only solution I found was using a NWConnection but this is super low level and now I need a shared session to manage cookies. If you want to see the NWConnection solution I made its here
func averageProxyGroupSpeed(proxies: [String], completion: @escaping (Int, String) -> Void) {
let numProxies = proxies.count
if numProxies == 0 {
completion(0, "No proxies")
return
}
var totalTime: Int64 = 0
var successCount = 0
let group = DispatchGroup()
let queue = DispatchQueue(label: "proxyQueue", attributes: .concurrent)
let lock = NSLock()
let shuffledProxies = proxies.shuffled()
let selectedProxies = Array(shuffledProxies.prefix(25))
for proxy in selectedProxies {
group.enter()
queue.async {
let proxyDetails = proxy.split(separator: ":").map(String.init)
guard proxyDetails.count == 4,
let port = Int(proxyDetails[1]),
let url = URL(string: "http://httpbin.org/get") else {
completion(0, "Invalid proxy format")
group.leave()
return
}
var request = URLRequest(url: url)
request.timeoutInterval = 15
let configuration = URLSessionConfiguration.default
configuration.connectionProxyDictionary = [
AnyHashable("HTTPEnable"): true,
AnyHashable("HTTPProxy"): proxyDetails[0],
AnyHashable("HTTPPort"): port,
AnyHashable("HTTPSEnable"): false,
AnyHashable("HTTPUser"): proxyDetails[2],
AnyHashable("HTTPPassword"): proxyDetails[3]
]
let session = URLSession(configuration: configuration)
let start = Date()
let task = session.dataTask(with: request) { _, _, error in
defer { group.leave() }
if let error = error {
print("Error: \(error.localizedDescription)")
} else {
let duration = Date().timeIntervalSince(start) * 1000
lock.lock()
totalTime += Int64(duration)
successCount += 1
lock.unlock()
}
}
task.resume()
}
}
group.notify(queue: DispatchQueue.main) {
if successCount == 0 {
completion(0, "Proxies Failed")
} else {
let averageTime = Int(Double(totalTime) / Double(successCount))
completion(averageTime, "")
}
}
}
Delegate example
class ProxySessionDelegate: NSObject, URLSessionDelegate {
let username: String
let password: String
init(username: String, password: String) {
self.username = username
self.password = password
}
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic {
let credential = URLCredential(user: self.username, password: self.password, persistence: .forSession)
completionHandler(.useCredential, credential)
} else {
completionHandler(.performDefaultHandling, nil)
}
}
}
Hello everyone,
I’m encountering an issue when trying to build and archive my library BleeckerCodesLib using Swift Package Manager. My project is structured with two targets:
CBleeckerLib: A C target that contains my image processing code (C source files and public headers).
BleeckerCodesLib: A Swift target that depends on CBleeckerLib and performs an import CBleeckerLib.
Below is the relevant portion of my Package.swift:
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "BleeckerCodesLib",
platforms: [.iOS(.v16)],
products: [
.library(name: "BleeckerCodesLib", targets: ["BleeckerCodesLib"])
],
targets: [
.target(
name: "CBleeckerLib",
publicHeadersPath: "include"
),
.target(
name: "BleeckerCodesLib",
dependencies: ["CBleeckerLib"]
)
]
)
Directory Structure
My project directory looks like this:
BleeckerCodesLib/
├── BleeckerCodesLib.xcodeproj/
│ └── xcuserdata/
│ └── robertopitarch.xcuserdatad/
│ └── xcschemes/
│ └── xcschememanagement.plist
├── BleeckerCodesLib.h
├── Package.swift
└── Sources/
├── CBleeckerLib/
│ ├── bleecker-lib.c
│ └── include/
│ ├── bleecker-lib.h
│ └── CBleeckerLib.h
└── BleeckerCodesLib/
├── UIImage+Extensions.swift
├── ImageProcessingUtility.swift
├── APIManager.swift
├── BleeckerCodesLib.swift
├── CameraView.swift
├── RealTimeCameraView.swift
└── BleeckerCameraWrapper.swift
Code Example
In my Swift code (for example, in BleeckerCodesLib.swift), I import the C module as follows:
import SwiftUI
import UIKit
import CBleeckerLib // Import the C module
public struct BleeckerCodes {
public struct DetectedCode {
public let code: String
public let corners: [CGPoint]
public init(code: String, corners: [CGPoint]) {
self.code = code
self.corners = corners
}
}
// Initialization function
public static func initializeLibrary() -> String {
bleecker_init() // Call the C module function
return "BleeckerCodesLibrary initialized!"
}
// ... other functions
}
The Problem
When I try to compile or archive the project using commands such as:
xcodebuild archive -project BleeckerCodesLib.xcodeproj -scheme BleeckerCodesLib -destination "generic/platform=iOS" -archivePath "archives/BleeckerCodesLib"
I receive the error: "no such module 'CBleeckerLib'"
Any assistance or step-by-step guidance on resolving this integration issue would be greatly appreciated.
Thank you in advance!
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Swift Packages
Developer Tools
Frameworks
Compiler
My project uses a local swift package of my own, which uses SwiftGenPlugin to generate image resources. I can archive the project locally, but Xcode Cloud doesn't work and reports an error: "SwiftGenPlugin" is disabled.