Swift is a powerful and intuitive programming language for Apple platforms and beyond.

Posts under Swift tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

watchOS app crashing on devices running watchOS 11+
We have a watchOS app in TestFlight that is currently crashing on any device running watchOS 11 and up. I have an older Apple Watch SE that's capped at 10.6.1 that can run the app just fine, but the same exact install on a newer device fails. This started happening after I updated my MacBook to macOS Sequoia and Xcode to 16. In order to get the Watch app to run on the 10.6.1 device, I had to change the Swift Optimization Level from -O to -Osize. I already filed Feedback on this (FB15691116). I've tried so many different things and have come up with nothing to show for it. When I look in the IPS file, I see that the crash point in my code on the watchOS 11 device is at KinesiaUOnWatch`@objc SessionDelegator.session(_:activationDidCompleteWith:error:): 0x3a3f48 <+0>: sub sp, sp, #0x60 0x3a3f4c <+4>: stp x26, x25, [sp, #0x10] 0x3a3f50 <+8>: stp x24, x23, [sp, #0x20] 0x3a3f54 <+12>: stp x22, x21, [sp, #0x30] 0x3a3f58 <+16>: stp x20, x19, [sp, #0x40] 0x3a3f5c <+20>: stp x29, x30, [sp, #0x50] 0x3a3f60 <+24>: add x29, sp, #0x50 0x3a3f64 <+28>: mov x19, x4 0x3a3f68 <+32>: mov x23, x2 0x3a3f6c <+36>: mov x22, x0 0x3a3f70 <+40>: mov w0, #0x0 ; =0 0x3a3f74 <+44>: bl 0x89818 ; symbol stub for: type metadata accessor for Swift.MainActor 0x3a3f78 <+48>: mov x24, x0 0x3a3f7c <+52>: adrp x25, 161 0x3a3f80 <+56>: ldr w25, [x25, #0x654] 0x3a3f84 <+60>: mov x20, x0 0x3a3f88 <+64>: bl 0x8980c ; symbol stub for: static Swift.MainActor.shared.getter : Swift.MainActor 0x3a3f8c <+68>: mov x21, x0 0x3a3f90 <+72>: adrp x0, 166 0x3a3f94 <+76>: add x0, x0, #0xc40 ; lazy protocol witness table cache variable for type Swift.MainActor and conformance Swift.MainActor : Swift.Actor in Swift Incident Identifier: 08E2F667-7965-4C86-B85E-9E2F03EAA963 Beta Identifier: AD390666-55CB-43B3-9B14-BD3E70F456EB Hardware Model: Watch6,1 Process: KinesiaUOnWatch [389] Path: /private/var/containers/Bundle/Application/B571E983-F2B0-40EF-9F0D-8C471CAEB3FB/KinesiaUOnWatch.app/KinesiaUOnWatch Identifier: com.glneurotech.kinesiau.watchapp Version: 5.1.0 (510271) AppStoreTools: 16B39 AppVariant: 1:Watch6,1:11 Beta: YES Code Type: ARM64_32 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.glneurotech.kinesiau.watchapp [464] Date/Time: 2024-12-03 15:12:51.1876 -0500 Launch Time: 2024-12-03 15:12:50.0000 -0500 OS Version: Watch OS 11.1 (22R585) Release Type: User Report Version: 104 Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000002053dd4c Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [389] But, as I said, this exact app runs just fine on an older watchOS 10.6.1 device. Has anyone else encountered something like this, or have any ideas on stuff to try?
0
0
41
4h
existential any error in MLModel class
Problem I have set SWIFT_UPCOMING_FEATURE_EXISTENTIAL_ANY at Build Settings > Swift Compiler - Upcoming Features to true to support this existential any proposal. Then following errors appears in the MLModel class, but this is an auto-generated file, so I don't know how to deal with it. Use of protocol 'MLFeatureProvider' as a type must be written 'any MLFeatureProvider' Use of protocol 'Error' as a type must be written 'any Error' environment Xcode 16.0 Xcode 16.1 Beta 2 What I tried Delete cache of DerivedData and regenerate MLModel class files I also tried using DepthAnythingV2SmallF16P6.mlpackage to verify if there is a problem with my mlmodel I tried the above after setting up Swift6 in Xcode I also used coremlc to generate MLModel class files with Swift6 specified by command.
0
2
76
14h
Identifying memory leaks
I'm having an issue with my swiftui macOS application where it is continually consuming more memory over time and after a couple of hours will grind to a halt. I've watched a few videos now on how to use Xcode Memory Graph and Instruments to identify the source of a leak (I assume it is a leak). These videos all provide very obvious issues as examples but mine seems more elusive and I don't know how to identify which part of my code is the cause of the issue. After running instruments I see the following but the leaked objects are not always consistent: Xcode Memory Graph shows NSSet as the culprit which is shown under CoreFoundation (not my App). I really am a beginner here and because it's not showing me somewhere in my app that I can go and investigate I'm really stuck.
0
0
80
22h
How to Create a Designated Keychain for Testing Purposes?
I wrote a Keychain controller that add, delete and fetch keychain items using SecItemAdd(_:_:)and related APIs with data protection keychain enabled (kSecUseDataProtectionKeychain). I am using it in a macOS Cocoa app. I am using Swift Testing to write my tests to ensure that the controller works as expected. As I understand, I should create my own keychain for testing rather than use the actual keychain in macOS. Currently, I created a separate keychain group (e.g. com.testcompany.testapp.shared) and added it to myapp.entitlements file so that the tests pass without failing because of the missing entitlement file. SecKeychainCreate(_:_:_:_:_:_:) and SecKeychainDelete(_:) API are deprecated with no alternative provided in the documentation. I noticed SecKeychain class but documentation doesn't explain much about it. How should I test my keychain controller properly so that it does not use the actual macOS keychain, which is the "production" keychain?
2
0
96
4h
How to handle dynamic pricing in consumable in app purchase programatically in swift?
In an application feature where users can purchase resources to enhance the exposure, visibility, or engagement of specific content (such as boosting videos, posts, or other user-generated content), the price needs to adjust dynamically based on the user-selected budget. How can this type of In-App Purchase flow be implemented in iOS Swift? Also checked link for tax category: https://developer.apple.com/help/app-store-connect/manage-app-information/set-a-tax-category
0
0
39
1d
Does the videoDeviceNotAvailableWithMultipleForegroundApps Interruption Occur on iPhones?
Hello, I am developing a service using capture sessions. I have a question concerning something curious I've noticed. Occasionally, I've been informed that the capture session stops working. Upon investigation, I found records of the videoDeviceNotAvailableWithMultipleForegroundApps interruption on the devices. From what I've looked up in the documents, it seems to occur due to multitasking capabilities, but I'm wondering if there are any specific scenarios where this happens on iPhone devices? Here is the relevant documentation link: https://developer.apple.com/documentation/avfoundation/avcapturesession/interruptionreason/videodevicenotavailablewithmultipleforegroundapps I suspect it might have something to do with Picture-in-Picture (PIP) mode, but when I developed and tested a direct video streaming PIP, the issue did not occur. Does anyone have insights on this matter or related experiences they could share?
0
0
83
2d
Error: Value of type 'SettingsView' has no member 'tabItem'
I'm going through the tutorial and have copied the code given to me verbatim, but I am still getting the error 'Value of type 'SettingsView' has no member 'tabItem'. Not sure what to do. Code is below. import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { TabView { ContentView() .tabItem { Label("Journal", systemImage: "book") } SettingsView() .tabItem { *error is here - Value of type 'SettingsView' has no member 'tabItem' Label("Settings", systemImage: "gear") } } } } }
1
0
112
2d
Per-project ProjectName-Swift.h, rather than per-target
Dear Experts, I have an Xcode project that generates two iOS app targets. Most of the code is shared between the two targets. Let's call them "Project", "App1" and "App2". I have some Swift code that is called from objC++. To make this work, in the objC++ files currently I #include "App1-Swift.h". Clearly this only works when building App1. What's the right way to set this up to work for both targets? Looking at the build settings, currently the "Generated Header Name" is set to "$(SWIFT_MODULE_NAME)-Swift.h". Presumably, SWIFT_MODULE_NAME expands to the target name. There are various possible ways to fix this, but which one is "right"? I bet that if I fix it in the wrong way, something else will go wrong later. I could: Change the objC++ to #include different headers depending on the target being built. Change the build setting to use the project name (from a variable?) instead of the SWIFT_MODULE_NAME. Somehow cause SWIFT_MODULE_NAME to equal the project name, rather than the target name. Any advice? Thanks.
0
0
107
3d
boringss1_metrics_log_metric_block_invoke (153) Failed to log metrics
i created a new project and imported firebaseauth , firebasefirestore, firebasefirestoreswift and firebase storage and i run this project any time i run this project the code they are all fine i get this error saying boringss1_metrics_log_metric_block_invoke (153) Failed to log metrics anytime i click create account button note that i get them results in my firebase authentication but it seems not to pass the registration page in my project and prints that error i am stuck somebody please save me even when i try to login the already created account from the userSection from the auth.authservice it still shows this error and wont pass the login page same with the registration page
0
0
92
5d
Expected expression after operator error
Hello, I am going through the swift tutorial and am experiencing an 'expected expression after operator' error in when I am trying to add the favorite button. I'm not quite sure how to fix it. Below is the code and where the error is. import SwiftUI struct LandmarkDetail: View { @Environment(ModelData.self) var modelData var landmark: Landmark var landmarkIndex: Int{ modelData.landmarks.firstIndex(where: { $0.id == landmark.id}) ! } **_expected expression after operator_** var body: some View { @Bindable var modelData = modelData ScrollView { MapView(coordinate: landmark.locationCoordinates) .frame(height: 300) CircleImage(image: landmark.image) .offset(y:-130)
1
0
114
5d
Xcode 16.2 Beta 3 makes min deploy to iOS 16 for swift/cpp mixed projects
Below copied from my original post here: https://forums.swift.org/t/xcode-16-2-beta-seems-increase-the-min-deploy-to-16-0-for-swift-cpp-mixed-project/76221 Our games are set to min deploy of iOS 12.0. When building with the Xcode 16.2 beta3, the Xcode 16.1 build-able project will have errors for those static libs that has swift mixed with C++: Compiling for iOS 12.0, but module 'Cxx' has a minimum deployment target of iOS 16.0: /Users/trout.zhang/Documents/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/Cxx.swiftmodule/arm64-apple-ios.swiftmodule Change that static lib min deploy to 16.0 can make the build succeed, while maintain the exe target still use iOS 12.0. I am not familiar with how the min deploy works, is it: choosing the highest of exe and its dependencies, thus effectively set the final product has min deploy of iOS 16.0 or maintaining exe's iOS 12.0 and actually crash in runtime if the iOS is less than 16.0, when reach the code in that static lib. Apparently, non of the above is what we want. Use cat in cmdline, for Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/Cxx.swiftmodule/arm64-apple-ios.swiftdoc with both Xcode.app(16.1) and Xcode-beta.app(16.2 beta3), I found the different lines: Xcode 16.1 has: Apple Swift version 6.0.2 effective-5.10 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)Cxx?arm64-apple-ios11.0 Xcode 16.2 beta 3 has: Apple Swift version 6.0.3 effective-5.10 (swiftlang-6.0.3.1.8 clang-1600.0.30.1)Cxx?arm64-apple-ios16.0
0
0
107
5d
Typographic question for space character
In this UIKit app, I have to display numbers (from 1 to 100), in a label., on several lines, with 8 numbers on each line. Order is computed by the app for a specific purpose. The numbers are separated by space. Label font is Helvetica Neue 15.0. I want to get them aligned vertically. So, I have a padding so that they are all the same length of 4. Problem: the space have smaller width (half in fact) than digits, so alignment is disrupted: Of course, I can use fixed width fonts (like Menlo), but I've not found one that fits (the zero is barred, which is not looking great in the app). I have tried using class func monospacedDigitSystemFont( ofSize fontSize: CGFloat, weight: UIFont.Weight ) -> UIFont and apply to label.text. To no avail as it modifies only digits, not space char. I have found a workaround, padding with 2 spaces instead of one, but is there another solution ? So I am looking for a space character that would have the same width as a digit. There existe thin space (https://en.wikipedia.org/wiki/Whitespace_character) but not larger space. Does it exist ?
4
0
114
5d
SafariBookmarksSyncAgent quits unexpectedly
Since recently (maybe after updating to Sonoma 14.7.1 - 23H222, but not sure, I get a crash report stating that SafariBookmarksSyncAgent quitted unexpectedly Once acquitted the report, it will reappear 2 minutes later as long as Xcode is open. Configuration: Sonoma 14.7.1 Safari Technology Preview Release 208 (Safari 18.2, WebKit 19621.1.5.1) Xcode 15.3 (15E204a) That seems to be a known problem. Question: Is it due to MacOS version ? To Xcode version ? To Safari version ? To webKit version ? Or to simulator, as I gat an AegirPoster crash (as described here: https://stackoverflow.com/questions/77083912/macbook-pro-crashes-when-using-simulator-aegirposter-process) I read that I would need to restart some devices (eg, iPhone). That seems to temporarily solve the problem Here is a part of the report: Incident Identifier: 0D2456DF-5801-41D6-8294-2BF442224913 CrashReporter Key: 4DE33529-174E-32C5-D8A8-26FE128BE16B Hardware Model: Mac14,12 Process: SafariBookmarksSyncAgent [38972] Path: /Volumes/VOLUME/*/SafariSupport.bundle/SafariBookmarksSyncAgent Identifier: com.apple.SafariBookmarksSyncAgent Version: 8614 (8614.1.25.0.17) Code Type: ARM-64 (Native) Role: Unspecified Parent Process: launchd_sim [28070] Coalition: com.apple.CoreSimulator.SimDevice.0058D576-D9FF-4169-8437-D0A24C923500 [9832] Responsible Process: SimulatorTrampoline [1116] Date/Time: 2024-11-27 15:19:42.4908 +0100 Launch Time: 2024-11-27 15:19:42.4610 +0100 OS Version: macOS 14.7.1 (23H222) Release Type: User Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000204476580 Exception Codes: 0x0000000000000001, 0x0000000204476580 VM Region Info: 0x204476580 is not in any region. Bytes after previous region: 894002561 Bytes before following region: 58984012416 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL VM_ALLOCATE 1cefdc000-1cefe0000 [ 16K] r--/rwx SM=PRV ---> GAP OF 0xdf1020000 BYTES commpage (reserved) fc0000000-1000000000 [ 1.0G] ---/--- SM=COW reserved VM address space (unallocated) Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [38972] Triggered by Thread: 0 Thread 0 Crashed: 0 dyld_sim 0x104f9dc7c dyld4::SyscallDelegate::forEachInDirectory(char const*, bool, void (char const*, char const*) block_pointer) const + 172 1 dyld_sim 0x104f88b6c invocation function for block in dyld4::ProcessConfig::PathOverrides::processVersionedPaths(dyld4::ProcessConfig::Process const&, dyld4::SyscallDelegate&, dyld4::ProcessConfig::DyldCache const&, dyld3::Platform, dyld3::GradedArchs const&, lsl::Allocator&) + 104 2 dyld_sim 0x104f88aa0 dyld4::ProcessConfig::PathOverrides::forEachInColonList(char const*, char const*, bool&, void (char const*, bool&) block_pointer) + 224 3 dyld_sim 0x104f886b8 dyld4::ProcessConfig::PathOverrides::processVersionedPaths(dyld4::ProcessConfig::Process const&, dyld4::SyscallDelegate&, dyld4::ProcessConfig::DyldCache const&, dyld3::Platform, dyld3::GradedArchs const&, lsl::Allocator&) + 144 4 dyld_sim 0x104f882a8 dyld4::ProcessConfig::PathOverrides::PathOverrides(dyld4::ProcessConfig::Process const&, dyld4::ProcessConfig::Security const&, dyld4::ProcessConfig::Logging const&, dyld4::ProcessConfig::DyldCache const&, dyld4::SyscallDelegate&, lsl::Allocator&) + 344 5 dyld_sim 0x104f868b8 dyld4::ProcessConfig::ProcessConfig(dyld4::KernelArgs const*, dyld4::SyscallDelegate&, lsl::Allocator&) + 152 6 dyld_sim 0x104f85e30 _dyld_sim_prepare + 352 7 dyld 0x10492fa8c dyld4::prepareSim(dyld4::RuntimeState&, char const*) + 1276 8 dyld 0x10492e4f0 dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 308 9 dyld 0x10492def4 start + 1868 I filed a bug report: Nov 27, 2024 at 3:41 PM – FB15976427
0
0
67
6d
EXC_BAD_ACCESS KERN_INVALID_ADDRESS ,Crashed: com.apple.main-thread
I am experiencing a crash on iOS 18 for some devices when the app becomes active again after being inactive for one or two days, with the following details: Crash Information: Thread: com.apple.main-thread Exception: EXC_BAD_ACCESS KERN_INVALID_ADDRESS The crash occurs intermittently on certain devices, but I haven’t been able to reproduce it consistently. Based on the crash logs, it seems to be related to accessing an invalid or corrupted memory address. But if user try to uninstall the app or restart the device, the issue is gone . Is this a known issue in iOS 18? Are there any official workarounds or fixes? Could this be related to specific device configurations, such as limited memory on older models? Are there any known APIs or frameworks in iOS 18 that could trigger such an issue? What additional debugging steps would you recommend to narrow down the root cause? Have other developers encountered similar crashes in iOS 18? Thank you for your help! I appreciate any insights or suggestions.
1
0
76
12h
Diffable Data Source Warning: Non-Thread Confined Updates
Hello, I’ve encountered a warning while working with UITableViewDiffableDataSource. Here’s the exact message: Warning: applying updates in a non-thread confined manner is dangerous and can lead to deadlocks. Please always submit updates either always on the main queue or always off the main queue - view=&lt;UITableView: 0x7fd79192e200; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = &lt;NSArray: 0x600003f3c9f0&gt;; backgroundColor = &lt;UIDynamicProviderColor: 0x60000319bf80; provider = &lt;NSMallocBlock: 0x600003f0ce70&gt;&gt;; layer = &lt;CALayer: 0x6000036e8fa0&gt;; contentOffset: {0, -116}; contentSize: {375, 20}; adjustedContentInset: {116, 0, 49, 0}; dataSource: &lt;TtGC5UIKit29UITableViewDiffableDataSourceOC17ArticleManagement21DiscardItemsViewModel17SectionIdentifierSS: 0x600003228270&gt;&gt; OS: iOS Version: iOS 17+, Xcode Version: 16.0, Frameworks: UIKit, Diffable Data Source, View: UITableView used with a UITableViewDiffableDataSource. Steps to Reproduce: Using a diffable data source with a table view. Applying snapshot updates in the data source from a main thread. Warning occurs intermittently during snapshot application. Expected Behavior: The snapshot should apply without warnings, provided the updates are on a main thread. Actual Behavior: The warning suggests thread safety issues when applying updates on non-thread-confined queues. Questions: Is there a recommended best practice to handle apply calls in diffable data sources with thread safety in mind? Could this lead to potential deadlocks if not addressed? Note :- I confirm I am always reloading / reconfiguring data source on main thread. Please find the attached screenshots for the reference. Any guidance or clarification would be greatly appreciated!
0
0
176
1d
Not authorized to send Apple events to Microsoft Excel
I have created swift command line project and i have added logic to executing apple script using NSAppleScript. That will launch Microsoft Excel file I am launching this swift command line executable from java using process launch. 3)This is not prompting me. It is throwing exception "Not authorized to send Apple events to Microsoft Excel." I have already tried out this option Added info.plist with NSAppleEventsUsageDescription Added entitlement with com.apple.security.automation.apple-events to true In packages i have selected this entitlement i have select the bundle identifier , team and signing certificate "Development" and automatically manage signing. can you please suggest what could i missed ?
1
0
115
14h