Hello! I'm developing a SDK and a customer is experiencing a very rare crash (happening for < 10 users) for which there are no clear repro steps.
In the attached backtrace of the crash, there are two threads #13 and #17 which seem to be accessing the same part of the code (named MyMethod2 in the file). Thread #17 is the one crashing during deallocation of some protobuf objects.
We designed MyMethod2 to be called by at most one thread at any point in time by using a serial DispatchQueue.
My question is: can we tell for sure that the threads #13 and #17 shown in the file were executing that shared code simultaneously just by looking at the trace? If so, there'd be a concurrency bug in my code that I need to fix, but I haven't found anything suspicious. If on the other hand, these two threads were both used by the serial queue but at different times, then the problem is elsewhere.
Thank you for your help!
The two threads:
Thread 13 name:
Thread 13:
0 libsystem_kernel.dylib 0x00000001f61a0cb0 write (libsystem_kernel.dylib)
1 CoreFoundation 0x00000001aed14f68 fileWrite (CoreFoundation)
2 CoreFoundation 0x00000001aed14c40 CFWriteStreamWrite (CoreFoundation)
3 [MyHiddenAppName] 0x0000000107b81f8c NSOutputStream.write(_:)
4 [MyHiddenAppName] 0x0000000107ab6640 specialized MyMethod2
5 [MyHiddenAppName] 0x0000000107ab6cf0 partial apply for closure #1 in MyMethod1
6 [MyHiddenAppName] 0x0000000102ba0538 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>:0)
7 libdispatch.dylib 0x00000001b6c4f6a8 _dispatch_call_block_and_release (libdispatch.dylib)
[...]
Thread 17 name:
Thread 17 Crashed:
0 libswiftCore.dylib 0x00000001a8467d70 _swift_release_dealloc (libswiftCore.dylib)
1 libswiftCore.dylib 0x00000001a8469424 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) (libswiftCore.dylib)
2 [MyHiddenAppName] 0x0000000107a45b54 destroy for MyProtoStruct4
3 [MyHiddenAppName] 0x0000000107a55c64 outlined destroy of (MyProtoStruct2.OneOfEnum, MyProtoStruct2.OneOfEnum)
4 [MyHiddenAppName] 0x0000000107a4503c MyProtoStruct4._StorageClass.__deallocating_deinit
5 libswiftCore.dylib 0x00000001a8467d88 _swift_release_dealloc (libswiftCore.dylib)
6 libswiftCore.dylib 0x00000001a8469424 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) (libswiftCore.dylib)
7 [MyHiddenAppName] 0x0000000107a6a91c destroy for MyProtoStruct3
[...]
80 [MyHiddenAppName] 0x0000000107ab6108 specialized MyMethod2
81 [MyHiddenAppName] 0x0000000107ab6cf0 partial apply for closure #1 in MyMethod1
82 [MyHiddenAppName] 0x0000000102ba0538 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>:0)
83 libdispatch.dylib 0x00000001b6c4f6a8 _dispatch_call_block_and_release (libdispatch.dylib)
[...]
crash_backtrace.txt
Dive into the world of programming languages used for app development.
Post
Replies
Boosts
Views
Activity
I am try to extract the audio file url from Shazamkit, it is deep inside the hierarchy of SHMediaItem > songs > previewAssets > url
when I access the url with like this:
let url = firstItem.songs[0].previewAssets?[0].url
I am getting a warning like this:
here is the Variable Viewer
this is what I have done so far:
struct MediaItems: Codable {
let title: String?
let subtitle: String?
let shazamId: String?
let appleMusicId: String?
let appleMusicUrL: URL?
let artworkUrl: URL?
let artist: String?
let matchOffset: TimeInterval?
let videoUrl: URL?
let webUrl: URL?
let genres: [String]
let isrc: String?
let songs: [Song]?
}
extension SwiftFlutterShazamKitPlugin: SHSessionDelegate{
public func session(_ session: SHSession, didFind match: SHMatch) {
let mediaItems = match.mediaItems
if let firstItem = mediaItems.first {
// extracting the url
let url = firstItem.songs[0].previewAssets?[0].url
let _shazamMedia = MediaItems(
title:firstItem.title!,
subtitle:firstItem.subtitle!,
shazamId:firstItem.shazamID!,
appleMusicId:firstItem.appleMusicID!,
appleMusicUrL:firstItem.appleMusicURL!,
artworkUrl:firstItem.artworkURL!,
artist:firstItem.artist!,
matchOffset:firstItem.matchOffset,
videoUrl:firstItem.videoURL!,
webUrl:firstItem.webURL!,
genres:firstItem.genres,
isrc:firstItem.isrc!,
songs:firstItem.songs
)
do {
let jsonData = try JSONEncoder().encode([_shazamMedia])
let jsonString = String(data: jsonData, encoding: .utf8)!
self.callbackChannel?.invokeMethod("matchFound", arguments: jsonString)
} catch {
callbackChannel?.invokeMethod("didHasError", arguments: "Error when trying to format data, please try again")
}
}
}
Hello,
I am developing a feature for my app using a Share Extension to import voice recordings from Apple's Voice Memos app. My objective is to capture the title (sometimes user-modified) of the recording when it is shared to my app via the Share Extension.
While I am able to extract the default metadata (such as location-based titles) of the recordings, I am facing difficulties in accessing the titles that users have manually edited within the Voice Memos app. For example, if a user renames a memo to "Dinner with friends" this updated title does not seem to be accessible from the metadata provided when the memo is shared to my extension. Instead, I am only able to retrieve the original, automatic title such as "New Recording 19" or a street address.
Through testing, I've observed that when sharing a voice memo via the system share sheet to apps like Mail, the updated title is included as the subject of the email. This indicates that the updated title is available somewhere within the share sheet's context.
Could anyone provide guidance on how to access this updated title from the shared voice memo? Is there a specific type identifier or a property of NSExtensionItem that I should be using to retrieve this piece of information?
Here's a snippet of how I am currently accessing the shared content:
for item in self.extensionContext?.inputItems as? [NSExtensionItem] ?? [] {
for attachment in item.attachments ?? [] {
if attachment.hasItemConformingToTypeIdentifier(UTType.audio.identifier) {
// Processing the attachment
}
}
}
iam new to ios swift development
Hi --
I would like to be able to pass a Swift Array to C++ code. I know it should be possible, but having trouble figuring out the right way to do it. Here is an example class showing what I want to do.
C++ code:
class Foo {
public:
Foo(const std::vector<uint8_t> & values) : _values(values) {}
protected:
std::vector<uint_8> _values;
};
Swift code:
let values: [UInt8] = [ 1, 2, 3, 4, 5, 6 ]
var foo = Foo(values)
If I do this, I get the following error message: Cannot convert value of type '[UInt8]' to expected argument type 'std.__1.vector<UInt8, allocator<UInt8>>'.
I've been asked to update our app from the current metal code to Metal 3, and one of the concerns is whether we have to worry about any changed or deprecated features. Is there a way to confirm that our app won't behave differently now that it's under Metal 3? I am able to compile the iOS app targeting iOS 16, and shaders and pipelines are working as expected, is that proof enough that we are good to go? I don't see any version declarations or import dependencies to specific metal versions (ie. like in openGL where you would declare the shader version with #version 150 or something)...
Hi there,
I’m having issue using Apple’s API. I can’t initialize SFAuthorizationPluginView using Swift.
I’ve done numerous google searches, but haven’t found any examples/tutorials of anyone using Swift for SFAuthorizationPluginView / AuthorizationPluginCreate.
I managed to get the AuthorizationPlugin and AuthorizationMechanism up, but simply creating the SFAuthorizationPluginView fails the failable initiator.
https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginview
Here are some log messages I wrote:
error 16:08:33.689244-0800 kernel Library Validation failed: Rejecting '/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' (Team ID: 7X6364JT77, platform: no) for process 'SecurityAgentHel(2689)' (Team ID: N/A, platform: yes), reason: mapping process is a platform binary, but mapped file is not
error 16:08:33.689501-0800 SecurityAgentHelper-arm64 Error loading /Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent (78): dlopen(/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent, 0x0106): tried: '/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' (code signature in <BFF0D7BA-5CF8-3F2F-A604-DCC235499234> '/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' not valid for use in process: mapping process is a platform binary, but mapped file is not), '/System/Volumes/Preboot/Cryptexes/OS/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' (no such file), '/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' (code signature in <BFF0D7BA-5CF8-3F2F-A604-DCC235499234> '/Library/Security/SecurityAgentPlugins/XXXAgent.bundle/Contents/MacOS/XXXAgent' not valid for use in process: mapping process is a platform binary, but mapped file is not)
default 16:08:33.760679-0800 SecurityAgentHelper-arm64 callbacks: Optional(0x00000001001b1f88)
default 16:08:33.760710-0800 SecurityAgentHelper-arm64 andEngineRef: Optional(0x0000000156f384d0)
error 16:08:33.762404-0800 SecurityAgentHelper-arm64 Test API call result: OSStatus 0 i.e. No error.
error 16:08:33.763298-0800 SecurityAgentHelper-arm64 Failed to create Authorization Plugin Adapter
default 16:08:33.763524-0800 authd engine 66: running mechanism XXXAgent:XXXAgentMechanism (1 of 1)
Here is the calling code with the error message:
class AuthorizationMechanismXXX : AuthorizationMechanism
{
let mLogger = …
let mAuthorizationPluginView : AuthorizationPluginViewAdapter?
override init(inPlugin: UnsafeMutablePointer<AuthorizationPlugin>,
inEngine: AuthorizationEngineRef,
inMechanismId: AuthorizationMechanismId)
{
…
let pCallbacks : UnsafePointer<AuthorizationCallbacks> = inPlugin.pointee.EngineCallback()
self.mAuthorizationPluginView = AuthorizationPluginViewAdapter(callbacks: pCallbacks, andEngineRef: inEngine)
if (self.mAuthorizationPluginView == nil)
{
mLogger.error("Failed to create Authorization Plugin Adapter")
}
super.init(inPlugin: inPlugin, inEngine: inEngine, inMechanismId: inMechanismId)
}
Here is the class:
class AuthorizationPluginViewAdapter : SFAuthorizationPluginView
{
let mLogger = …
let mLoginView = NSHostingView(rootView: LoginView())
override init!(callbacks: UnsafePointer<AuthorizationCallbacks>!, andEngineRef engineRef: AuthorizationEngineRef!)
{
mLogger.notice("callbacks: \(callbacks.debugDescription, privacy: .public)")
mLogger.notice("andEngineRef: \(engineRef.debugDescription, privacy: .public)")
var sessionId: UnsafeMutablePointer<AuthorizationSessionId?>?
let result = callbacks.pointee.GetSessionId(engineRef, sessionId)
LogSecurityOSStatus(logger: mLogger, osStatus: result, message: "Test API call result")
super.init(callbacks: callbacks, andEngineRef: engineRef)
mLogger.notice("Never gets here")
}
override func buttonPressed(_ inButtonType: SFButtonType)
{
if (inButtonType == SFButtonTypeOK)
{
let osStatus = callbacks().pointee.SetResult(engineRef(), AuthorizationResult.allow)
if (osStatus != errSecSuccess)
{
LogSecurityOSStatus(logger: mLogger, osStatus: osStatus, message: "Error setting authorization result")
}
}
else if (inButtonType == SFButtonTypeCancel)
{
let osStatus = callbacks().pointee.SetResult(engineRef(), AuthorizationResult.deny)
if osStatus != errSecSuccess
{
LogSecurityOSStatus(logger: mLogger, osStatus: osStatus, message: "Error setting authorization result")
}
}
else
{
mLogger.error("Invalid buttonType.")
}
}
override func view(for inType: SFViewType) -> NSView!
{
if (inType == SFViewTypeIdentityAndCredentials)
{
mLogger.debug("Identity and credentials")
}
else if (inType == SFViewTypeCredentials)
{
mLogger.debug("Credentials only")
}
else
{
mLogger.error("Invalid buttonType.")
}
return mLoginView
}
}
Here is the view:
import SwiftUI
struct LoginView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
#Preview {
LoginView()
}
Hello. iOS 15 and its version of Swift had an issue with applying class level annotations, such as @available to the members of its class. When we attempt to use our Objective-C library to get the class, if there are things inside the class not available on iOS 15, then the call to objc_getClass crashes with EXC_BAD_ACCESS. This appears to have been fixed on iOS 16 and newer, however, as we still support iOS 15, is there a better workaround than having to annotate every needed member of the class with @available, instead of being able to use the class level annotation?
I have a demo app to explain how mergeable libraries work and I am stuck when archiving.
I have:
Project Demo
App Target
Framework A
Framework B
External Framework Project C (sub-project to Project Demo)
Framework C
I have all three frameworks in the demo project's dependencies, linking and embedding. Implicitly find dependencies is OFF (because that is how the actual app I will be applying this to is built)
I can build to sim/device for Debug and for Release. It all works. I can find my embedded resources. I have checked the binaries with otool -l and I can see where frameworks are loaded in Debug but not in Release. Yay!
But when I Archive the app, I get an error only for my External framework (not in the same project as the app) that it cannot find the file ExternalC.framework/ExternalC, even though if I copy the path, the file exists.
Build input file cannot be found: '/Users/MYUSER/Library/Developer/Xcode/DerivedData/MergeableLibrariesDemo-afgemdngqmoznfhczuxrqzkeulhb/Build/Intermediates.noindex/ArchiveIntermediates/MergableLibraries/BuildProductsPath/Release-iphoneos/ExternalC.framework/ExternalC'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'MergeableLibrariesDemo' from project
Here are the linker commands for the three frameworks:
-Xlinker -merge_library -Xlinker /Users/MYUSER/Library/Developer/Xcode/DerivedData/MergeableLibrariesDemo-afgemdngqmoznfhczuxrqzkeulhb/Build/Intermediates.noindex/ArchiveIntermediates/MergableLibraries/BuildProductsPath/Release-iphoneos/ExternalC.framework/ExternalC
-Xlinker -merge_framework -Xlinker SameProjectA
-Xlinker -merge_framework -Xlinker SameProjectB
Oh ExternalC.framework is an alias to the framework in the Uninstalled Products path
This is only an issue if ExternalC has this set:
//:configuration = Debug
MERGEABLE_LIBRARY = YES
//:configuration = Release
MERGEABLE_LIBRARY = YES
//:completeSettings = some
MERGEABLE_LIBRARY
Any clues as to what I might have misconfigured?
Steve
I have a MacOS application that has a non-consumable in-app purchase that unlocks an enhanced version of the app (in other words, it's a one-time upgrade purchased inside of the app). The transaction is handled using StoreKit 2 and the app is distributed on the MacOS App Store.
I would like to add an affiliate-like program where certain people can promote my application and receive a percentage of the earnings from users that buy the in-app purchase as a result of their promotion. In order to correctly distribute earnings, I need some way to track that a purchase from a user is linked to a certain affiliate.
Research led me to offer codes but I quickly realised that these are only valid for subscriptions (which my purchase is not), and, besides, it seems they are not supported on MacOS. Another constraint that I have is that my application should not make any external network requests (apart from those to Apple servers, like StoreKit), so I cannot use something like Firebase for a custom offer implementation.
I'm not sure what the best way to achieve this is. One way I thought of is to create one non-consumable in-app purchase/product for each affiliate and use a deep link to associate a user with that product. Then, I'll know which affiliate each user comes from based on the product that was used during the purchase. The only problem with this is that products need to be aded at compile-time so each new affiliate I add would require me to publish a new app version.
I'm wondering whether there's a better way to do this?
Hello, I'm currently facing an issue after adding the HaishinKit framework to my project, and I require immediate assistance. I’ve seen many questions regarding this kind of log but haven’t found any solution that fixes this problem.
My project is extensive, consisting of multiple modules and projects. Specifically, I have a module named TelegramUI where the HaishinKit framework has been successfully added and is functioning correctly. Now, I'm trying to add the same framework to another module called Social. I used Swift Package Manager to add the framework, providing the GitHub link and selecting the same version as in TelegramUI. After successfully building the app, it crashes upon launch, and I received the following log. It's worth noting that when I remove the framework from the Social module, everything works normally again.
dyld[490]: Library not loaded: @rpath/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct
Referenced from: <68034630-FB0B-34CA-B6E6-45967056914E> /private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/TelegramUI.framework/TelegramUI
Reason: tried: '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/TelegramUI.framework/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file)Library not loaded: @rpath/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct
Referenced from: <88CED3C3-284D-3F63-9AB2-585C5F26E4C0> /private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/SocialUI.framework/SocialUI
Reason: tried: '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/SocialUI.framework/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file, not in dyld cache), '/private/preboot/Cryptexes/OS/usr/lib/swift/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file), '/private/var/containers/Bundle/Application/7EF5BCB5-4C9C-4CCA-86E8-C9B3332E7BE4/Roobinet.app/Frameworks/HaishinKit_-79AB4CDABF03AA0A_PackageProduct.framework/HaishinKit_-79AB4CDABF03AA0A_PackageProduct' (no such file)
Hi,
How is it possible to check if I have a new mail? Is it possible to do it with ScriptingBridge?
Thank you!
I need to search some informations about some apps on App Store but by searching online I can find any information about APIs to do that. Do they exist?
Hi! I am working on an app for Vision Pro. I would like to create a SideBar in a view that shows different topics, that you can click on. Firstly, I need help understanding how to create a SideBar. Also, I have already made the different topics that will be displayed on the SideBar but I don't know how to link the SideBar up to the topics view. For example, if a user clicks on Maple Trees as a topic in the SideBar, it would take them to a new window that talks about Maple Trees.
If you can help, that would be great!
Hello,
I'm developing an app for Mac, Xcode 15.1, with Swift 5.
I need to create a visual matrix, whose elements will be filled randomly, according to the choices the user makes.
The matrix must have 10 columns and 40 rows.
Does anyone know a component, or how to fill it dynamically and randomly?
Thanks.
I have used this example to create the following code:
import Foundation
import CoreLocation
let monitorName = "BeaconMonitor"
let testBeaconId = UUID(uuidString: "EDFA3FFA-D80A-4C23-9104-11B5B0B8E8F3")!
@MainActor
public class ObservableMonitorModel: ObservableObject {
private let manager: CLLocationManager
public var monitor: CLMonitor?
init() {
self.manager = CLLocationManager()
self.manager.requestWhenInUseAuthorization()
self.manager.requestAlwaysAuthorization()
}
func startMonitoringConditions() {
Task {
monitor = await CLMonitor(monitorName)
await monitor!.add(getBeaconIdentityCondition(), identifier: "Beacon")
for identifier in await monitor!.identifiers {
guard let lastEvent = await monitor!.record(for: identifier)?.lastEvent else { continue }
print(identifier, lastEvent.state)
}
for try await event in await monitor!.events {
print("Event", event.identifier, event)
}
}
}
}
func getBeaconIdentityCondition() -> CLMonitor.BeaconIdentityCondition {
CLMonitor.BeaconIdentityCondition(uuid: testBeaconId)
}
Unfortunately, running this on my iPhone only prints "Beacon CLMonitoringState". I don't see anything from the for try await block starting with "Event".
Any ideas where I've gone wrong?
Context: I am trying to create a XCFramework that I can reuse it in my Swift app. My example is based on SPM (Swift Package Manager) but I had the same import error no such module when I tried to import my XCFramework in XCode.
Here is the code for XCFramework:
Package.swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "MySDK",
platforms: [.macOS(.v14), .iOS(.v13), .watchOS(.v6)],
products: [
.library(name: "MySDK", type: .dynamic, targets: ["MySDK"]),
],
targets: [
.target(name: "MySDK")
]
)
Sources/MySDK/my_sdk.swift
public func myHelloStr() -> String {
return "Bonjour le monde!"
}
To generate the XCFramework:
$ xcodebuild build -scheme MySDK -destination "platform=macOS" -derivedDataPath DerivedData SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
$ xcodebuild -create-xcframework -framework DerivedData/Build/Products/Debug/PackageFrameworks/MySDK.framework -output MyFramework.xcframework
I can see MyFramework.xcframework folder with
- `Info.plist`
- `macos-x86_64/MySDK.framework/MySDK`
- `macos-x86_64/MySDK.framework/Resources/Info.plist`
- `macos-x86_64/MySDK.framework/Versions/A/MySDK`
- `macos-x86_64/MySDK.framework/Versions/A/Resources/Info.plist`
- `macos-x86_64/MySDK.framework/Versions/Current/MySDK`
- `macos-x86_64/MySDK.framework/Versions/Current/Resources/Info.plist`
Then I create a new SPM project MyApp
with Package.swift
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "TestApp",
platforms: [.macOS(.v14), .iOS(.v13), .watchOS(.v6)],
products: [
.executable(name: "MyApp", targets: ["MyApp"])
],
targets: [
.executableTarget(name: "MyApp",
dependencies: [
.target(name: "MyFramework")
]
),
.binaryTarget(
name: "MyFramework",
path: "../test_sdk/MyFramework.xcframework"
)
]
)
And Sources/MyApp/main.swift:
import MySDK
print("Hello World: \(myHelloStr())")
$ swift run
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/olivier/dev/test_app/Sources/MyApp/main.swift:1:8: error: no such module 'MySDK'
import MySDK
^
/Users/olivier/dev/test_app/Sources/MyApp/main.swift:1:8: error: no such module 'MySDK'
import MySDK
^
error: fatalError
If I generate my XCFramework using xcodebuild archive instead of xcodebuild build such as described in this doc https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle:
$ xcodebuild archive -scheme MySDK -destination "platform=macOS" -derivedDataPath DerivedData -archivePath "archives/MyFramework" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
(...)
** ARCHIVE SUCCEEDED **
$ xcodebuild -create-xcframework -archive archives/MyFramework.xcarchive -framework MySDK.framework -output MyFramework.xcframework
error: the path does not point to a valid framework: /Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/Library/Frameworks/MySDK.framework
... it's not normal because I have these paths in /Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products:
/Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/Users/olivier/Objects/MySDK.o
/Users/olivier/dev/test_sdk/archives/MyFramework.xcarchive/Products/usr/local/lib/MySDK.framework/...
XCode version
$ xcodebuild -version
Xcode 15.2
Build version 15C500b
The application often crashes and I register an error in the log, see attachment, but I can't figure out where the problem might be.
Eureka.Section.subscript.getter (Swift.Int) Eureka.BaseRow.txt
Thank you very much for the advice
Wondering if anyone else is running into this.
It seems ModelConfiguration(isStoredInMemoryOnly: true) for previews (as outlined by Paul Hudson / Hacking with Swift) works correctly for
iOS + iCloud syncing
macOS WITHOUT iCloud syncing
But as soon as I turn on iCloud syncing capability for my macOS target, its as if the isStoredInMemoryOnly has no effect on the macOS target.
Here's my code...
I made a PreviewHelper to encapsulate the preview logic...
enum PreviewHelper {
static let previewModelContainer: ModelContainer = {
do {
let config = ModelConfiguration(isStoredInMemoryOnly: true)
let container = try ModelContainer(for: Task.self, configurations: config)
return container
} catch {
fatalError("Failed to create model container for previewing: \(error.localizedDescription)")
}
}()
}
And then use it like so...
#Preview {
let container = PreviewHelper.previewModelContainer
for task in MockData.tasks {
container.mainContext.insert(task)
}
return HorizonView()
.modelContainer(container)
}
On the macOS target & destination, using a macOS device in the Preview canvas, with iCloud syncing turned on that code inserts the MockData.tasks into my iCloud container every time the preview refreshes, so the data just keeps getting duplicated. With iCloud syncing turned off it behaves as expected/correctly (just inserting the MockData as needed for Previews).
In an iOS target, using the same helper and mock data, the helper behaves as expected/correctly (with or without iCloud syncing enabled).
Assuming this might be a bug/oversight with SwiftData and macOS? Or am I missing a needed configuration/capability on the macOS side? Anybody else seeing this?
hello
We are currently developing using Healthkit.
Starting with xcode15, healthkit throws an error.
The code causing the error is HKQuantityType(.stepCount).
When I use this code
An EXC_BAD_ACCESS (code=1, address=0x0) error occurs.
The error is:
AppDelegate
It also appears when I call didFinishLaunchingWithOptions.
Is the linker the problem?
Or is the Swift version the problem?
Or HealthKit?
Cleaning and initializing DerivedData
I also tried downgrading DriverKit 22.4, but the error still appears.
Please tell me how to solve this problem.
Test model information is as follows:
-iPhone 14 Pro
iOS 16.5.1