Dive into the world of programming languages used for app development.

All subtopics
Posts under Programming Languages topic

Post

Replies

Boosts

Views

Activity

How do I locate and this Bundle Error
❌ Could not find email_ai.py in the app bundle. Available files: [] The error above is what I’m encountering. I’ve placed the referenced file both in the project directory and inside the app. However, every time I remove and reinsert the file into the folder within the app, it prompts me to designate the targets—I select all, but this doesn’t resolve the issue. I’m unsure how to properly reference the file so that it is recognised and included in the bundle. Any guidance would be greatly appreciated. this is my build phase: #!/bin/sh set -x # Prints each command before running it (for debugging) pwd # Shows the current working directory echo "$SRCROOT" # Shows what Xcode thinks is the project root ls -l "$SRCROOT/EmailAssistant/EmailAssistant/PythonScripts" # Lists files in the script folder export PYTHONPATH="/Users/caesar/.pyenv/versions/3.11.6/bin" /Users/caesar/.pyenv/versions/3.11.6/bin/python3 "$SRCROOT/EmailAssistant/EmailAssistant/PythonScripts/email_ai.py" echo "Script completed."
1
0
445
Feb ’25
Missing libclang_rt.osx.a library on OSX
I tried to install the flang-new compiler from Homebrew on Sequoia OSX. Complex division is broken because file divdc3 is missing. This file comes from libclang_rt.osx.a, a standard LLVM library. This library is missing on OSX. program test integer, parameter :: n=2 complex(kind=8), dimension(n,n) :: V complex(kind=8) :: PER V(1,1)=cmplx(4.0,2.0) V(2,2)=cmplx(5.0,3.0) V(1,2)=0.0 V(2,1)=0.5 PER=cmplx(1.2,1.2) V(:,:)=V(:,:)/PER end program test alainhebert@Alains-MacBook-Air-2 test_complex % flang-new test.f90 Undefined symbols for architecture arm64: “___divdc3”, referenced from: __QQmain in test-fc2bb3.o ld: symbol(s) not found for architecture arm64 flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
2
0
658
Dec ’24
TaskExecutor and Swift 6 question
I have the following TaskExecutor code in Swift 6 and is getting the following error: //Error Passing closure as a sending parameter risks causing data races between main actor-isolated code and concurrent execution of the closure. May I know what is the best way to approach this? This is the default code generated by Xcode when creating a Vision Pro App using Metal as the Immersive Renderer. Renderer @MainActor static func startRenderLoop(_ layerRenderer: LayerRenderer, appModel: AppModel) { Task(executorPreference: RendererTaskExecutor.shared) { //Error let renderer = Renderer(layerRenderer, appModel: appModel) await renderer.startARSession() await renderer.renderLoop() } } final class RendererTaskExecutor: TaskExecutor { private let queue = DispatchQueue(label: "RenderThreadQueue", qos: .userInteractive) func enqueue(_ job: UnownedJob) { queue.async { job.runSynchronously(on: self.asUnownedSerialExecutor()) } } func asUnownedSerialExecutor() -> UnownedTaskExecutor { return UnownedTaskExecutor(ordinary: self) } static let shared: RendererTaskExecutor = RendererTaskExecutor() }
1
0
819
Dec ’24
Causes of disordered dictionary in Swift
Everyone knows that dictionaries in swift are unordered collections, there is no problem with that. I've noticed some behavior that I can't explain and hope someone can help me. The first variant We have a very simple code: struct Test { let dict = [1: “1”, 2: “2”, 3: “3”, 4: “4”, 5: “5”] func test() { for i in dict { print(i) } } } If you call test() several times in a row, the output to the console on my computer looks something like this: (key: 5, value: “5”) (key: 1, value: “1”) (key: 2, value: “2”) (key: 3, value: “3”) (key: 4, value: “4”) (key: 2, value: “2”) (key: 3, value: “3”) (key: 1, value: “1”) (key: 4, value: “4”) (key: 5, value: “5”) (key: 1, value: “1”) (key: 3, value: “3”) (key: 2, value: “2”) (key: 5, value: “5”) (key: 4, value: “4”) At each new for loop we get a random order of elements It seemed logical to me, because a dictionary is an unordered collection and this is correct behavior. However The second variant the same code on my colleague's computer, but in the console we see something like this: (key: 2, value: “2”) (key: 3, value: “3”) (key: 1, value: “1”) (key: 4, value: “4”) (key: 5, value: “5”) (key: 2, value: “2”) (key: 3, value: “3”) (key: 1, value: “1”) (key: 4, value: “4”) (key: 5, value: “5”) (key: 2, value: “2”) (key: 3, value: “3”) (key: 1, value: “1”) (key: 4, value: “4”) (key: 5, value: “5”) always, within the same session, we get the same order in print(i) We didn't use Playground, within which there may be differences, but a real project. swift version 5+ we tested on Xcode 14+, 15+ (at first I thought it was because the first version had 14 and the second version had 15, but then a third colleague with Xcode 15 had the behavior from the first scenario) we did a lot of checks, several dozens of times and always got that on one computer random output of items to the console, and in another case disordered only in the first output to the console Thanks
4
0
410
Dec ’24
Best way to convert HTML to PDF in a C# app on macOS?
I'm working on a cross-platform C# application that converts HTML content to PDF. The goal is to render dynamic HTML pages (including CSS and JavaScript) as high-quality, printable PDF files. Additionally, I need to support features like adding headers/footers, securing PDFs with passwords, and controlling user permissions. While everything works well on Windows, I need some help rendering consistency and handling permissions on MacOS.
6
0
868
Dec ’24
Passkey Creation SDK does not return Timeout Error on FaceID authentication times out.
We would like to show a user-friendly message but can not. Description: When attempting to create a duplicate passkey using the ASAuthrorizationController in iOS, the Face ID authentication times out SDK does not return a timeout specific error. Instead, it directly returns an error stating that duplicate passkey cannot be created. SDK to first handle the FaceID timeout case and provide a distinct timeout error so we can gracefully manage this scenario before the duplicate passkey validation occurs. Steps to Reproduce: Implement passkey creation flow using ASAuthorizationController. Attempt to register a duplicate passkey (e.g., using the same user ID and challenge). Let FaceID prompt timeout (do not interact with the authentication prompt).
0
0
244
Dec ’24
UIViewRepresentable is not working
I have been trying to integrate a UIKit view into SwiftUI, specifically a WKWebView. However, I keep encountering a does not conform to protocol error. Here's my code: import SwiftUI import WebKit struct SimpleWebView: View { var body: some View { WebViewContainerRepresentable() .edgesIgnoringSafeArea(.all) } } struct WebViewContainerRepresentable: UIViewRepresentable { typealias UIViewType = WKWebView func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() if let url = Bundle.main.url(forResource: "index", withExtension: "html") { webView.loadFileURL(url, allowingReadAccessTo: url.deletingLastPathComponent()) } return webView } func updateUIView(_ uiView: WKWebView, context: Context) { // Updates not required for this use case } } I tried this with other views as well, and it turns out this is not WKWebView-specific. The minimum deployment version is iOS 15. Any help would be much appreciated. Let me know if I need to add any more information.
1
0
577
Dec ’24
Inquiry about WebRTC camera access when using Chrome browser and WKWebView API on iPadOS
We are Java application developers and we have a question regarding camera access via WebRTC on iPadOS. Specifically, on iPadOS 17.1, we are encountering an issue when trying to access the camera via the WKWebView API in the Chrome browser, where an error occurs and the camera capture fails. Our investigation suggests that device access through the navigator.mediaDevices property via the WKWebView API may not work in Chrome. However, it works as expected in the Safari browser, leading us to wonder if this is a Chrome-specific limitation, or if it's due to an iPadOS setting or specification. At this point, we are unsure if this issue is related to the WKWebView and WebRTC specifications on iPadOS 17.1, or if there are specific limitations in Chrome. We would appreciate any insights or solutions regarding camera access in iPadOS 17.1 with WKWebView and WebRTC, especially in relation to Chrome.
1
0
533
Dec ’24
Can i use c++ in swift app project
Can i use c++ library with c library in swift app project Hello. I want to use a C++ library in my Swift app project. First, our company has an internal solution library. When built, it generates a Static Library in '.a' format, and we use it by connecting the library's Header to the App_Bridging_Header. There's no problem with this part. However, the new feature now includes C++. It also generates a Static Library in '.a' format. So, I tried to use the same method and created an App_Bridging_Header. But an error occurs, and I can't proceed. The first error occurs in the library file: 'iostream' file not found The second error occurs in the App_Bridging_Header: failed to emit precompiled header '/Users/kimjitae/Library/Developer/Xcode/DerivedData/ddddd-glmnoqrwdrgarrhjulxjmalpyikr/Build/Intermediates.noindex/PrecompiledHeaders/ddddd-Bridging-Header-swift_3O89L0OXZ0CPD-clang_188AW1HK8F0Q3.pch' for bridging header '/Users/kimjitae/Desktop/enf4/ddddd/ddddd/ddddd-Bridging-Header.h' Our library is developed in C++ using Xcode, and there's no problem when we run and build just the library project. The build succeeds, and the '.a' file is generated correctly. However, when we try to connect it with the app, the above problems occur. Could there be a problem because we also need to use the existing C library alongside this? The build is successful in an app project created with Objective-C.
4
0
617
Oct ’24
Swift6 race warning
I'm trying to fix some Swift6 warnings, this one seems too strict, I'm not sure how to fix it. The variable path is a String, which should be immutable, it's a local variable and never used again inside of the function, but still Swift6 complains about it being a race condition, passing it to the task What should I do here to fix the warning?
4
0
591
Jan ’25
Under Swift 6 on Sequoia, why is ContiguousArray suddenly so slow to allocate
I generate images with command line apps in Swift on MacOS. Under the prior Xcode/MacOS my code had been running at the same performance for years. Converting to Swift 6 (no code changes) and running on Sequoia, I noticed a massive slowdown. Running Profile, I tracked it down to allow single line: var values = ContiguousArray<Double>(repeating: 0.0, count: localData.options.count) count for my current test case is 4, so its allocating 4 doubles at a time, around 40,000 times in this test. This one line takes 42 seconds out of a run time of 52 seconds. With the profile shown as: 26 41.62 s  4.8% 26.00 ms specialized ContiguousArray.init(_uninitializedCount:) 42 41.57 s  4.8% 42.00 ms _ContiguousArrayBuffer.init(_uninitializedCount:minimumCapacity:) 40730 40.93 s  4.7% 40.73 s _swift_allocObject_ 68 68.00 ms  0.0% 68.00 ms std::__1::pair<MallocTypeCacheEntry*, unsigned int> swift::ConcurrentReadableHashMap<MallocTypeCacheEntry, swift::LazyMutex>::find<unsigned int>(unsigned int const&, swift::ConcurrentReadableHashMap<MallocTypeCacheEntry, swift::LazyMutex>::IndexStorage, unsigned long, MallocTypeCacheEntry*) 7 130.00 ms  0.0% 7.00 ms swift::swift_slowAllocTyped(unsigned long, unsigned long, unsigned long long) which is clearly inside the OS allocator somewhere. What happened? Previously this would have taken closer to 8 seconds or so for the entire run.
3
0
632
Oct ’24
percentages
I want to know how to format doubles. In the program I have 4.3333 I just want to print 4 to the screen. I just want to print whole numbers. I'm using Swiftui with xcode. Please help. Thank you.
3
0
264
Dec ’24
The Peril of the Ampersand
A few years ago [1] Xcode added new warnings that help detect a nasty gotcha related to the lifetime of unsafe pointers. For example: Initialization of 'UnsafeMutablePointer<timeval>' results in a dangling pointer Inout expression creates a temporary pointer, but argument 'iov_base' should be a pointer that outlives the call to 'init(iov_base:iov_len:)' I’ve seen a lot of folks confused by these warnings, and by the lifetime of unsafe pointers in general, and this post is my attempt to clarify the topic. If you have questions about any of this, please put them in a new thread in the Programming Languages > Swift topic. Finally, I encourage you to watch the following WWDC presentations: WWDC 2020 Session 10648 Unsafe Swift WWDC 2020 Session 10167 Safely manage pointers in Swift These cover some of the same ground I’ve covered here, and a lot of other cool stuff as well. Share and Enjoy — Quinn “The Eskimo!” Apple Developer Relations, Developer Technical Support, Core OS/Hardware let myEmail = "eskimo" + "1" + "@apple.com" [1] Swift 5.2.2, as shipped in Xcode 11.4. See the discussion of SR-2790 in Xcode 11.4 Release Notes. Basics In Swift, the ampersand (&) indicates that a parameter is being passed inout. Consider this example: func addVarnish(_ product: inout String) { product += " varnish" } var waffle = "waffle" addVarnish(&waffle) // line A print(waffle) // printed: waffle varnish On line A, the ampersand tells you that waffle could be modified by addVarnish(_:). However, there is another use of ampersand that was designed to help with C interoperability. Consider this code: var tv = timeval() gettimeofday(&tv, nil) print(tv) // printed: timeval(tv_sec: 1590743104, tv_usec: 77027) The first parameter to gettimeofday is an UnsafeMutablePointer<timeval>. Here the ampersand denotes a conversion from a timeval to an UnsafeMutablePointer<timeval>. This conversion makes it much easier to call common C APIs from Swift. This also works for array values. For example: var hostName = [CChar](repeating: 0, count: 256) gethostname(&hostName, hostName.count) print(String(cString: hostName)) // printed: slimey.local. In this code the ampersand denotes a conversion from [CChar] to an UnsafeMutablePointer<CChar> that points to the base of the array. While this is convenient, it’s potentially misleading, especially if you come from a C background. In C-based languages, using ampersand in this way yields a pointer to the value that’s valid until the value gets deallocated. That’s not the case in Swift. Rather, the pointer generated by the ampersand syntax is only valid for the duration of that function call. To understand why that’s the case, consider this code: struct TimeInTwoParts { var sec: time_t = 0 var usec: Int32 = 0 var combined: timeval { get { timeval(tv_sec: sec, tv_usec: usec) } set { sec = newValue.tv_sec usec = newValue.tv_usec } } } var time = TimeInTwoParts() gettimeofday(&time.combined, nil) // line A print(time.combined) // printed: timeval(tv_sec: 1590743484, tv_usec: 89118) print(time.sec) // printed: 1590743484 print(time.usec) // printed: 89118 Here combined is a computed property that has no independent existence in memory. Thus, it simply makes no sense to take the address of it. So, how does ampersand deal with this? Under the covers the Swift compiler expands line A to something like this: var tmp = time.combined gettimeofday(&tmp, nil) time.combined = tmp Once you understand this it’s clear why the resulting pointer is only valid for the duration of the call: As soon as Swift cleans up tmp, the pointer becomes invalid. A Gotcha This automatic conversion can be a nasty gotcha. Consider this code: var tv = timeval() let tvPtr = UnsafeMutablePointer(&tv) // line A // ^~~~~~~~~~~~~~~~~~~~~~~~~ // Initialization of 'UnsafeMutablePointer<timeval>' results in a dangling pointer gettimeofday(tvPtr, nil) // line B This results in undefined behaviour because the pointer generated by the ampersand on line A is no longer valid when it’s used on line B. In some cases, like this one, the later Swift compiler is able to detect this problem and warn you about it. In other cases you’re not so lucky. Consider this code: guard let f = fopen("tmp.txt", "w") else { … } var buf = [CChar](repeating: 0, count: 1024) setvbuf(f, &buf, _IOFBF, buf.count) // line A let message = [UInt8]("Hello Crueld World!".utf8) fwrite(message, message.count, 1, f) // line B fclose(f) // line C This uses setvbuf to apply a custom buffer to the file handle. The file handle uses this buffer until after the close on line C. However, the pointer created by the ampersand on line A only exists for the duration of the setvbuf call. When the code calls fwrite on line B the buffer pointer is no longer valid and things end badly. Unfortunately the compiler isn’t able to detect this problem. Worse yet, the code might actually work initially, and then stop working as you change optimisation settings, update the compiler, change unrelated code, and so on. Another Gotcha There is another gotcha associated with the ampersand syntax. Consider this code: class AtomicCounter { var count: Int32 = 0 func increment() { OSAtomicAdd32(1, &count) } } This looks like it’ll implement an atomic counter but there’s no guarantee that the counter will be atomic. To understand why, apply the tmp transform from earlier: class AtomicCounter { var count: Int32 = 0 func increment() { var tmp = count OSAtomicAdd32(1, &tmp) count = tmp } } So each call to OSAtomicAdd32 could potentially be operating on a separate copy of the counter that’s then assigned back to count. This undermines the whole notion of atomicity. Again, this might work in some builds of your product and then fail in other builds. Note The above discussion is now theoretical because Swift 6 added a Synchronization module that includes comprehensive support for atomics. That module also has a Mutex type (if you need a mutex on older platforms, check out OSAllocatedUnfairLock). These constructs use various different mechanisms to ensure that the underlying value has a stable address. Summary So, to summarise: Swift’s ampersand syntax has very different semantics from the equivalent syntax in C. When you use an ampersand to convert from a value to a pointer as part of a function call, make sure that the called function doesn’t use the pointer after it’s returned. It is not safe to use the ampersand syntax for functions where the exact pointer matters. It’s Not Just Ampersands There’s one further gotcha related to arrays. The gethostname example above shows that you can use an ampersand to pass the base address of an array to a function that takes a mutable pointer. Swift supports two other implicit conversions like this: From String to UnsafePointer<CChar> — This allows you to pass a Swift string to an API that takes a C string. For example: let greeting = "Hello Cruel World!" let greetingLength = strlen(greeting) print(greetingLength) // printed: 18 From Array<Element> to UnsafePointer<Element> — This allows you to pass a Swift array to a C API that takes an array (in C, arrays are typically represented as a base pointer and a length). For example: let charsUTF16: [UniChar] = [72, 101, 108, 108, 111, 32, 67, 114, 117, 101, 108, 32, 87, 111, 114, 108, 100, 33] print(charsUTF16) let str = CFStringCreateWithCharacters(nil, charsUTF16, charsUTF16.count)! print(str) // prints: Hello Cruel World! Note that there’s no ampersand in either of these examples. This technique only works for UnsafePointer parameters (as opposed to UnsafeMutablePointer parameters), so the called function can’t modify its buffer. As the ampersand is there to indicate that the value might be modified, it’s not used in this immutable case. However, the same pointer lifetime restriction applies: The pointer passed to the function is only valid for the duration of that function call. If the function keeps a copy of that pointer and then uses it later on, Bad Things™ will happen. Consider this code: func printAfterDelay(_ str: UnsafePointer<CChar>) { print(strlen(str)) // printed: 18 DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { print(strlen(str)) // printed: 0 } } let greeting = ["Hello", "Cruel", "World!"].joined(separator: " ") printAfterDelay(greeting) dispatchMain() The second call to strlen yields undefined behaviour because the pointer passed to printAfterDelay(_:) becomes invalid once printAfterDelay(_:) returns. In this specific example the memory pointed to by str happened to contain a zero, and hence strlen returned 0 but that’s not guaranteed. The str pointer is dangling, so you might get any result from strlen, including a crash. Advice So, what can you do about this? There’s two basic strategies here: Extend the lifetime of the pointer Manual memory management Extending the Pointer’s Lifetime The first strategy makes sense when you have a limited number of pointers and their lifespan is limited. For example, you can fix the setvbuf code from above by changing it to: let message = [UInt8]("Hello Crueld World!".utf8) guard let f = fopen("tmp.txt", "w") else { … } var buf = [CChar](repeating: 0, count: 1024) buf.withUnsafeMutableBufferPointer { buf in setvbuf(f, buf.baseAddress!, _IOFBF, buf.count) fwrite(message, message.count, 1, f) fclose(f) } This version of the code uses withUnsafeMutableBufferPointer(_:). That calls the supplied closure and passes it a pointer (actually an UnsafeMutableBufferPointer) that’s valid for the duration of that closure. As long as you only use that pointer inside the closure, you’re safe! There are a variety of other routines like withUnsafeMutableBufferPointer(_:), including: The withUnsafeMutablePointer(to:_:) function The withUnsafeBufferPointer(_:), withUnsafeMutableBufferPointer(_:), withUnsafeBytes(_:), and withUnsafeMutableBytes(_:) methods on Array The withUnsafeBytes(_:) and withUnsafeMutableBytes(_:) methods on Data The withCString(_:) and withUTF8(_:) methods on String. Manual Memory Management If you have to wrangle an unbounded number of pointers — or the lifetime of your pointer isn’t simple, for example when calling an asynchronous call — you must revert to manual memory management. Consider the following code, which is a Swift-friendly wrapper around posix_spawn: func spawn(arguments: [String]) throws -> pid_t { var argv = arguments.map { arg -> UnsafeMutablePointer<CChar>? in strdup(arg) } argv.append(nil) defer { argv.forEach { free($0) } } var pid: pid_t = 0 let success = posix_spawn(&pid, argv[0], nil, nil, argv, environ) == 0 guard success else { throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), userInfo: nil) } return pid } This code can’t use the withCString(_:) method on String because it has to deal with an arbitrary number of strings. Instead, it uses strdup to copy each string to its own manually managed buffer. And, as these buffers are manually managed, is has to remember to free them. Change History 2024-12-11 Added a note about the Synchronization module. Made various editorial changes. 2021-02-24 Fixed the formatting. Added links to the WWDC 2021 sessions. Fixed the feedback advice. Minor editorial changes. 2020-06-01 Initial version.
0
0
9.8k
Dec ’24
Is it possible to Add Reply of Push Notification from Airpod using Voice ?
We want to do below addition to iOS Mobile App. Airpod announces Push notification = which is workking now we want to use voice command that "Reply to this" and sending Reply to that notification but it is saying it is not supported in your app. So basically we need to use feature - Listen and respond to messages with AirPods Do we need to add any integration inside app for this or it will directly worked with Siri settings ? Is it possible to do in non messaging App? Is it possible to do without syncing contacts ?
0
0
481
Dec ’24
Open any Swift view from C++
I've narrowed down my question after many rabbit holes - how can C++ code open any view in Swift. I can call functions in swift from C++ (works great), but not async or main actor (or actor at all) functions. And if I'm not mistaken all views are actors if not main actors? When calling from C+ I think its necessary that the first view be the main actor? I've implemented the code from the WWDC23 C++ interop video (Zoe's image picker) where I made a view in a struct, and just want to call it and let the view do the work. The compiler immediately gives me 'cannot expose main actors to C++'. If I'm not mistaken, doesn't this block the opening of any kind of swift view from C++? Hopefully I'm missing something obvious, which is likely :) In Zoe's code was his entry point into the program still Swift and not actually C++ app? Thanks! Thanks!
1
0
105
May ’25
orientation transaction token
Hello Im having an error in swiftUI project of mine. I use fullscreencover to navigate through views. Normally it s been working but one point it doesn't. I go through MainMenu -> SomeOtherView -> GameView -> AfterGameView -> SomeOtherView -> MainMenu. When it comes to mainmenu at last, it s showing main menu for a glimpse of a look and then goes back to GameView. In console an error took my notice. > A new orientation transaction token is being requested while a valid one already exists. reason=Fullscreen transition (dismissing): fromVC=<_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10795ca00>; toVC=<_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x1071c3400>;; windowOrientation=portrait; sceneOrientation=portrait; existingTransaction=<_UIForcedOrientationTransactionToken: 0x600001804a40; state: active; originalOrientation: portrait (1)> Cant really finding the solution. Need help asap I will release a bug update to Appstore.
0
0
447
Jan ’25
Getting error on xcode 15.3 underlying Objective-C module 'FirebaseSharedSwift' not found
underlying Objective-C module 'FirebaseSharedSwift' not found aymodazhnyneylcscdggrsgjocui/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FirebaseSharedSwift.build/Objects-normal/x86_64/FirebaseSharedSwift.private.swiftinterface:5:19: underlying Objective-C module 'FirebaseSharedSwift' not found Command SwiftCompile failed with a nonzero exit code
0
0
491
Oct ’24
Collection and Index error on Xcode 16
Hi, After update to Xcode 16 a lot of errors happen, for example: import Foundation extension Collection {     func get(at i: Index) -&gt; Element? {         return indices.contains(i) ? self[i] : nil     } } Errors: Cannot find type 'Index' in scope Cannot find 'indices' in scope What is wrong? Thanks.
5
0
698
Sep ’24