Post not yet marked as solved
Hello,
we've been working with the Swift Chart framework, and the BarMark chart has a memory problem/bug when using it on the iPhone with iOS 16.0 Developer Beta 3.
Problem
When using the BarMark chart on the simulator with fake values, the chart load, however if we try to load the data on the iPhone, the code breaks with this error: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16d153ff8).
This however does not happen when we change the chart type from BarMark to LineMark. Then all of the sudden, the chart loads on the iPhone.
Now, when the error hits, Xcode show that the memory usage is extremely high.
Working Code
High Memory usage and error
Post not yet marked as solved
My iOS app consists of one app target and several local SPM packages. Previously, I had a test plan which only included the app target’s tests, while the packages’ tests were launched separately using the packages’ scheme names.
Now, I’m trying to switch to test plans entirely. I included the test targets defined in the packages in the test plan. However, doing so resulted in the following error message, attributed to @testable import statements:
Testing failed:
Module '<***>' was not compiled for testing
Command CompileSwiftSources failed with a nonzero exit code
Testing cancelled because the build failed.
If I understand it correctly, the error occurs because the Enable Testability (ENABLE_TESTABILITY) build setting defaults to NO, preventing the packages’ internal symbols from being exposed with @testable imports. Since Swift packages do not use Xcode project files, I’m confused about where I should define this setting. Besides that, testability is expected to be enabled only for test and not release builds, while Swift packages don’t support build configurations.
Am I missing something? Is there a way to make Swift packages and test plans play nice together?
Post not yet marked as solved
Hi,
I am developing an app which has a calendar integrated. This calendar comes from a package called CalendarKit (https://github.com/richardtop/CalendarKit ).
With this calendar you can access to all the events of you mobile integrated calendar and create new ones, modify them, delete, etc. All the events on you mobile calendar are going to be represented here and the same in the other way, everything that you create here will be represented on you mobile calendar.
So the main question is. How can i access to the 'Delete Event' action inside the 'Event Details' view?
I know that i can delete an event programmatically, but i need to "modify" the behavior when clicking on the item 'Delete Event'.
Is there any possible way to access to this item inside event details and when clicking on it do a custom action?.
For example, when clicking i want to:
print a text in the console,
show an alert,
get the EventID of the event deleted,
etc.
Can somebody help me with this??
Thanks a lot in advance.
Post not yet marked as solved
Given is an app project with two SPM dependencies: one to a source code repro and one to a repro containing in XCFramework. Using "Build Documentation" in Xcode generates the documentation for the app and source framework but not for the XCFramework.
Wonder, why the documentation is not generated from the symbol graph of the binary
Tried to create a .doccarchive with the framework using "Build Documentation during 'Build'" build setting, but:
.doccarchive is not copied when creating a XCFramework
after adding .doccarchive to XCFramework, it will not be resolved and downloaded via SPM
Is there any way to distribute the documentation of my binary framework over SPM to be displayed in the Documentsbrowser using the "Build Documentation" command?
Post not yet marked as solved
Swift Package Manager synthesises a module accessor for bundle resources (as described in WWDC 2020 Session 10169 Swift packages: Resources and localisation and SE-0271 > Runtime Access to Resources Bundle.
This is great, but I'd like to supply a different implementation of module. When I try to extend Bundle with my own module accessor the compiler complains that there are two module implementations. Is it possible to disable the SPM resource_bundle_accessor synthesis behaviour?
Post not yet marked as solved
How to get info about the exact version that is used in a build that is going for AppStore publications? Is it one specified in "iOS Deployment Target" in Build Settings?
My iOS app is published on AppStore. And users with different iOS versions can install it (15.0, 15.1, ..., 15.5, ...). To my understanding, Apple frameworks and packages like SwiftUI, Foundation, Combine, etc. can have differences for different iOS versions.
Post not yet marked as solved
Hello,
I want to add a .mlmodel to my swift package to have a test to verify that the compilation is working.
targets: [
.target(
name: "packageName",
dependencies: ["package1"]
),
.testTarget(
name: "packageNameTests",
dependencies: ["packageName"],
resources: [
.copy("Resources/testmodel.mlmodel"),
]
)
]
My problem is the .mlmodel is always as a compiled model after bundling
let docsPath = Bundle.module.resourcePath!
let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)
print(docsArray)
leads to
["testmodel.mlmodelc"]
I am excepting testmodel.mlmodel to be present instead. I find it strange that copy is processing the ressource. Is there a workaround ? I am using Xcode 14 beta but there is a similar post on StackOverflow without answer regarding this issue https://stackoverflow.com/questions/64298356/how-to-add-uncompiled-mlmodel-to-xcode-unittests-bundle that got this problem with Xcode 12
Thank you
Post not yet marked as solved
Hi -
I'm blocked by a spurious error in XCode I can't shake, in an iOS/Catalyst app project in swift with swift packages.
The target has an iOS deployment version of 14.1, but XCode UI behaves like the target is set to 13.0:
The package product 'LIB' requires minimum platform version 14.0 for the iOS platform, but this target supports 13.0
The command line builds fine:
xcodebuild -configuration Release -scheme 'Study (iOS)' # (also Debug config)
I'm sure I must be missing some configuration, but I have set the iOS/catalyst deployment version > 14 in project and target.
To confirm:
I'm using the same target scheme in XCode UI as the command-line build
I fail in the UI using any relevant target devices (i.e., over iOS 14, mac catalyst or ipad)
The project selector clearly shows target 14.1 (project/Deployment target/iOS deployment target)
The project/target UI clearly shows deployment target 14.1 (project view, 'Study (iOS)' target, iOS Deployment Target)
Same result when using version 15.0 instead of 14.1
Same result when disabling catalyst support and targeting iPad
Same result with or without a derived mac catalyst product bundle identifier
Same result for macOS targets 11..12.4
14.0 = macOS 11.0
15.0 = 12.0
Same result after creating a new run scheme.
Scanning all files in the project confirms these settings and does not show a relevant 13
e.g., in "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" and IPHONEOS_DEPLOYMENT_TARGET
I'm running macOS 12.4, XCode 13.4 (13F17a), default 5.6 toolchain, with packages declaring 5.6 toolchain
No external xcconfig files
In the XCode UI, I've done clean builds and reset the package cache
I've deleted XCode's Derived Data and restarted mac
I'm also developing packages (and have cleaned .build and .swiftpm directories) but app package dependencies are pulling from remote repository (i.e., not using local packages)
So:
Any clue as to why XCode believes the target is 13 and not 14.1?
How I can debug this?
Is there some way XCode can indicate the target triplet and SDK and how it is derived?
Is the next step to recreate the project?
Thanks!
Post not yet marked as solved
Hi all,
I have been facing a problem while loading a file from the firebase storage.
Basically in my code i have a data model which is the file/document (pdf in this case), a manager which goes into the database of Firebase to fetch the object and finally two views, one to list the files fetched and another one to show the document.
I can fetch all the documents with their specific data, pass them to my view and then show the document pdf in another view.
Everything seems correct but the problem comes when opening one of this docs. First, the doc doesn't open at first so you need to close the view and try to open the doc again. Then when i want to open another doc from my list, when i click on it the previous document is shown and not the correct one, so i need to do the same, close the view and click again on the doc to open the correct one.
So at the end what i'm looking for is to open the doc just clicking once but i don't know where is my problem.
List of docs:
1st time:
2nd time:
2nd doc but 1st time:
2nd doc and 2nd time clicking on it:
Here is my code
Model:
struct DocumentoPdf {
let titulo: String
let docUrl: URL?
let id: String
let storageUrl: String
}
Manager which fetches the documents from firebase:
final class DatabaseManager {
[...]
public func getNovedades(completion: @escaping ([DocumentoPdf]) -> Void) {
database.collection("novedades").getDocuments { snapshot, error in
guard let documents = snapshot?.documents.compactMap ({ $0.data() }), error == nil else {
return
}
let novedades: [DocumentoPdf] = documents.compactMap({ dictionary in
guard let id = dictionary["id"] as? String,
let titulo = dictionary["titulo"] as? String,
let docUrlString = dictionary["docUrl"] as? String,
let storageUrl = dictionary["storageUrl"] as? String else {
return nil
}
let novedad = DocumentoPdf(titulo: titulo,
docUrl: URL(string: docUrlString),
id: id,
storageUrl: storageUrl)
return novedad
})
completion(novedades)
}
}
}
First View:
class NovedadesViewControllerViewModel {
let docUrl: URL?
var docData: Data?
init(docUrl: URL?) {
self.docUrl = docUrl
}
}
class NovedadesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, PDFViewDelegate {
private var tableView = UITableView()
private var doc = PDFDocument()
public func configureDocPdf(with viewModel: NovedadesViewControllerViewModel) {
if let data = viewModel.docData {
doc = PDFDocument(data: data)!
}
else if let url = viewModel.docUrl {
// fetch doc & cache
let task = URLSession.shared.dataTask(with: url) { [weak self] data, _, _ in
guard let data = data else {
return
}
viewModel.docData = data
DispatchQueue.main.async {
self?.doc = PDFDocument(data: data)!
}
}
task.resume()
}
}
private var novedades: [DocumentoPdf] = []
private func obtenerNovedades() {
DatabaseManager.shared.getNovedades() { [weak self] novedades in
self?.novedades = novedades
DispatchQueue.main.async {
self?.tableView.reloadData()
}
}
}
override func viewDidLoad() {
[...]
obtenerNovedades()
[...]
}
[... sections, rows in section...]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let novedad = novedades[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = novedad.titulo
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let novedad = novedades[indexPath.row]
switch indexPath.section {
case 0:
configureDocPdf(with: .init(docUrl: novedad.docUrl))
let lectorPdfView = LectorPdfViewController(doc: self.doc, nameDoc: novedad.titulo)
self.present(lectorPdfView, animated: true, completion: nil)
default:
break
}
}
}
Second View to load the pdf:
class LectorPdfViewController: UIViewController, PDFViewDelegate {
private let navBar = UINavigationBar()
private let pdf = PDFView()
let nameDoc: String
let doc: PDFDocument
init(doc: PDFDocument, nameDoc: String) {
self.doc = doc
self.nameDoc = nameDoc
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError()
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
view.addSubview(navBar)
view.addSubview(pdf)
pdf.document = self.doc
pdf.delegate = self
let item = UINavigationItem(title: self.nameDoc)
navBar.setItems([item], animated: false)
navBar.barTintColor = .systemBackground
}
override func viewDidLayoutSubviews() {
navBar.frame = CGRect(x: 0,
y: 0,
width: view.frame.size.width,
height: 50)
pdf.frame = CGRect(x: 0,
y: navBar.frame.height,
width: view.frame.size.width,
height: view.frame.size.height - navBar.frame.height)
}
}
Please if someone can help me with this will be fantastic. I hope you understood my code and my problem. Sorry for my bad english
Thank you so much in advance
Post not yet marked as solved
Hi,
I am a developer working in a bank swift library that uses Chilkat iOS am. Currently, the library can be installed by Cocoapods. The podspec have these lines to let their installation:
s.source_files = ['Project/Classes/**/*', 'Project/Libs/ios-chilkat/include/**/*.h']
s.vendored_frameworks = ['Project/Libs/ios-chilkat/libchilkat.xcframework']
s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => ['-lresolv', '-lpthread', '-lstdc++'] }
s.dependency 'Alamofire', '~> 4.9.1'
s.dependency 'Dynatrace', '~> 8.215'
Now I have to make the library compatible with Swift Package Manager, by I can't achive it. When my library is imported, the "Cko**" classes are not recognized.
the package.swift have these lines:
.target(
...
dependencies: [
"Alamofire",
"libchilkat",
.product(name: "Dynatrace", package: "swift-mobile-sdk", condition:
.when(platforms: [.iOS]))
],
path: "Project",
sources: [
"Classes/.",
"Libs/chilkat-ios/include/."
]
)
...
I've been trying for a week now, what can I do?
Post not yet marked as solved
There is a package that I want to use in my iOS app project. Although it lacked certain functionality, the GitHub community is great and it was added by some kind soul.
However, as it was not yet merged with original repository, this functionality lives only in the fork. And that's when there came the trouble.
Although I'm supplying the Package Manager with the link to the fork, it does a great job in correcting me and points me to the original repo. I've seen that one can lock onto a specific commit hash in this article: https://www.swiftbysundell.com/articles/managing-dependencies-using-the-swift-package-manager/#adding-remote-dependencies, but it was only shown for Packages, not Projects in Xcode.
Is there a way out of it? Is there a file I could edit to bring me the functionality I crave before I grow old?
Post not yet marked as solved
Hi guys,
i'm encountering an issue that makes me crazy. Dunno if there's a solution available :D
I have a main apps that imports a lot of local SPM modules; some of them are considered base common models, imported by other modules (e.g.
Module1 is a base module with common resources for Module2 and Module3).
Unfortunately when i import all the modules, all the resources inside the Module1 seems not loaded (not found!) correctly.
Module1 (common model)
targets: [
.target(name: Module1,
dependencies: [],
resources: [
.process("Resources")
]),
Module2
targets: [
.target(name: Module2,
dependencies: [
.byName(name: Module1),
],
resources: [
.process("Resources")
]),
Module3
targets: [
.target(name: Module3,
dependencies: [
.byName(name: Module1),
],
resources: [
.process("Resources")
]),
Example of errors i'm encountering:
Calls from main app (.workspace) with imported SPM Module1, 2, 3.
Bundle.module.path(forResource: <xib file in Module1>, ofType: "nib") => nil
Bundle.module.loadNibNamed(<xib file in Module1>, owner: self, options: nil)?.first as? UIView => nil
Do you have any idea how to load correctly all the dependencies?
Post not yet marked as solved
I want to generate a DocC documentation for an internal Swift Package with the help of SwiftDocC plugin using the following command:
The internal framework uses realm-core and realm-cocoa.
$ swift package --disable-sandbox preview-documentation --product InternalFramework
Actual Results
If I build the DocC files via Xcode the build documentation is generated. But if I use the above command on the terminal to generate.
There is an error shown on the terminal and the framework fails to build the documentation.
The following is the error shown on the terminal
Computing version for https://github.com/realm/realm-cocoa.git
Computed https://github.com/realm/realm-cocoa.git at 10.28.1 (0.64s)
Computing version for https://github.com/realm/realm-core
Computed https://github.com/realm/realm-core at 12.1.0 (0.36s)
error: Couldn’t update repository submodules:
fatal: could not get a repository handle for submodule 'tools/vcpkg/ports'
I do not understand whether it is a DocC based issue or a realm issue.
Steps & Code to Reproduce
Running the following command causes the error:
$ swift package --disable-sandbox preview-documentation --product InternalFramework
I am not able to understand the root cause of the error.
Post not yet marked as solved
I work with a number of enterprise clients and one thing we often do is have various frameworks that are optional depending on what type of build we are doing. A common example being to include a framework that contains an embedded server for testing, demo or debugging purposes.
Prior to SPM we would link those frameworks as "Optional" and run a script phase after the build that removed them from the Frameworks directory of the app if it was a "Release" build.
Now I have an Xcode project that includes a number of SPM package, one of which is an embedded server which in turns references several other packages I'd like to exclude form a "Release" build.
But I cannot figure out how to do this. Can I make the inclusion of a package optional? Or somehow remove it after linking?
In Swift I can write #if canImport(MockServer) but I cannot see how to actually make MockServer an optional include.
Any ideas?
Post not yet marked as solved
I have a SPM framework project that includes both Swift code and JSON file resources.
With a package file that looks like this:
let package = Package(
name: "MyTestData",
products: [
.library(
name: "MyTestData",
targets: [
"MyTestData",
]
),
],
targets: [
.target(
name: "MyTestData",
dependencies: [],
path: "Sources",
sources: ["ios"],
resources: [
.copy("payloads"),
.copy("snippets"),
]
),
]
)
Now all the SPM packages resolve correctly and the code compiles and works, yet the Xcode workspace is showing errors like this:
Now payloads and snippets are not projects and I've tried all sorts of variations of path, sources, exclude, resource in my Package file and either I get the errors and everything works, or the errors disappear and the project doesn't work. I don't know what the issue is and there's nothing in the resolving or build logs.
Does anyone know what might be the problem here?
Post not yet marked as solved
The Situation
Our SwiftUI project uses three Swift packages (hosted on GitHub in private repositories):
a custom UIKit package
a custom BackendKit package
a custom ApplicationKit package
From the filesystem perspective it looks like this:
OurApplication/
CustomUIKitPackage/
CustomBackendKitPackage/
CustomApplicationKitPackage/
I added all three packages as local dependencies (because we need to edit them constantly) by dragging their folders into the project workspace. In the Xcode project navigator they are now under a Packages group.
I also added remote dependencies for all three packages to the Xcode project by using their git@github.com:... URL. Access to these three private repos are already granted.
The Problem
With this configuration I can work on the project and on all three packages as well. I can make changes, run tests, all the stuff - No problem.
Triggering an Xcode Cloud build it will always fail saying something weird of:
an out-of-date resolved file was detected at /Volumes/workspace/repository/MY_PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved, which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies. Running resolver because the following dependencies were added: 'CustomBackendKitPackage' (git@github.com:MY_COMPANY/CustomBackendKitPackage.git)xcodebuild: error: Could not resolve package dependencies:
Removing all three local dependencies out of MY_PROJECT/Packages/*, pushing everthing to GitHub and running an Xcode Cloud build again, it works as expected. All three remote dependencies with its git@github.com:... URLs are being used correctly and the Xcode Cloud build turns green.
The Question
How do I configure Xcode correctly so that I have my local packages for development at the same time as Xcode Cloud uses the remote references?
Post not yet marked as solved
I'm trying to use Previews in a Swift Package in Xcode 14b2 but it's not working (it was working in Xcode 13). I have the following error message but I don't know how to solve it.
"XCPreviewAgent.app" must be code signed in order to use on-device previews. Check your code signing settings for the target.
com.apple.dt.UVPreviewAgent-watchOS.watchkitapp {
url: file:///Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/Library/Xcode/Agents/XCPreviewAgent.app
version: 20.0.32.2
attributes: [
ObjectIdentifier(0x00000001638e5d18): ["OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1"],
]
}
Post not yet marked as solved
We tried to build with Xcode 14 and quickly ran into SPM issues, we have one binary submodule for a framework. Has something changed in how package location are described? Can't seem to find it as a legit framework. Can "cd" and inspect, everything appears to be in place.
Showing Recent Errors Only
local binary target 'Service.iOS' does not contain expected binary artifact named 'Service.iOS'
Works without issues in Xcode 13.4.1 and can switch between the versions.
Any ideas?
Post not yet marked as solved
Is there a logical disjunction operator or function in Swift?
Even better, is there a logical disjunction that works with optional variables instead of boolean variables that returns an object when true, and returns nil when false?
A logical disjunction evaluates two boolean variables, and if at least one of them is true, then the return value is true. If neither variables is true, then the return value is false.
Post not yet marked as solved
Hello,
i am currently trying to implement a pre build script execution in a package.
I am using this tutorial to implement it. But it only shows how to use the pre build feature with an already existing feature. I want to execute a skript on my pc every time i build the project.
I can't use apples prebuild skript feature in the build settings because it is a package.
Right now my code looks like this:
import Foundation
import OSLog
import PackagePlugin
@main struct GenerateLocalizer: BuildToolPlugin {
do {
let commandlineOutput = try shell("./testScript.sh")
} catch {
}
return [.prebuildCommand(displayName: "Generate Strings", executable: PackagePlugin.Path("./scrips/generate_strings.sh"), arguments: [], outputFilesDirectory: target.directory)]
}
func shell(_ command: String) throws -> String {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.standardError = pipe
task.arguments = [command]
os_log("%{public}@", log: log, task.arguments?.joined(separator: " ") ?? "not found")
task.launchPath = "/bin/zsh"
task.standardInput = nil
try task.run()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)!
return output
}
}
and my Package file looks something like that
name: "CustomSdk",
dependencies: ["CustomSdk-Objc"],
path: "CustomSdk",
exclude: ["Info.plist", "CustomSdk.podspec"],
plugins: [
.plugin(name: "GenerateLocalizer")
]
),
.plugin(name: "GenerateLocalizer",
capability: .buildTool(),
dependencies: ["CustomSdk-Objc"]
)
It gets called properly but when want to write files in my "testScript.sh" it only says: Operation not permitted.
Anyone got any ideas how to fix this or is there another way to utitlize custom scripts with custom packages?
Greetings
Ben