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

All subtopics
Posts under Programming Languages topic

Post

Replies

Boosts

Views

Activity

jmp_buf layout for Apple Silicon
Greetings! I am actively working on porting x64 code to Apple Silicon now that the time is nigh and part of the fundamentals of our software is a coroutine library for handling cooperative multitasking of GUI operations on the main thread. I was hoping to get the locations of the stack pointer and frame pointer in jmp_buf so, after setjmp() can redirect them to the primary handling routines in our coroutine library that handles the cooperative scheduling (which replaced and ported the old classic MP routines) which worked for PowerPC, i386 and x64. Any thoughts on where in the jmp_buf these might be located? I didn't see anything in the XNU open source. Any advice would be much obliged instead of having to dive in and re-implement these routines in assembly myself!
7
0
355
Aug ’25
Passing string between Swift and C++
I want to understand what the recommended way is for string interoperability between swift and c++. Below are the 3 ways to achieve it. Approach 2 is not allowed at work due to restrictions with using std libraries. Approach 1: In C++: char arr[] = "C++ String"; void * cppstring = arr; std::cout<<"before:"<<(char*)cppstring<<std::endl;           // C++ String // calling swift function and passing the void buffer to it, so that swift can update the buffer content Module1::SwiftClass:: ReceiveString (cppstring, length);   std::cout<<"after:"<<(char*)cppstring<<std::endl;             // SwiftStr      In Swift: func ReceiveString (pBuffer : UnsafeMutableRawPointer , pSize : UInt ) -> Void { // to convert cpp-str to swift-str: let swiftStr = String (cString: pBuffer.assumingMemoryBound(to: Int8.self)); print("pBuffer content: \(bufferAsString)"); // to modify cpp-str without converting: let swiftstr:String = "SwiftStr"      _ =  swiftstr.withCString { (cString: UnsafePointer<Int8>) in pBuffer.initializeMemory(as: Int8.self, from: cString, count: swiftstr.count+1) } }  Approach 2:  The ‘String’ type returned from a swift function is received as ‘swift::String’ type in cpp. This is implicitly casted to std::string type. The std::string has the method available to convert it to char *. void TWCppClass::StringConversion () {     // GetSwiftString() is a swift call that returns swift::String which can be received in std::string type     std::string stdstr = Module1::SwiftClass::GetSwiftString ();     char * cstr = stdstr.data ();     const char * conststr= stdstr.c_str (); }    Approach 3: The swift::String type that is obtained from a swift function can be received in char * by directly casting the address of the swift::String. We cannot directly receive a swift::String into a char *. void TWCppClass::StringConversion () {    // GetSwiftString() is a swift call that returns swift::String    swift::String swiftstr = Module1::SwiftClass::GetSwiftString ();    // obtaining the address of swift string and casting it into char *    char * cstr = (char*)&swiftstr; }
3
0
383
Jul ’25
Structured concurrency + preconcurrency API (SFAuthorizationPluginView)
I'm having trouble dealing with concurrency with the SFAuthorizationPluginView. Does anybody know how this can be solved? https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginview The crux of it is: If I inherit an object as part of an API, and the API is preconcurrency, and thus is nonisolated (but in reality is @MainActor), how do I return a @MainActor GUI element? https://developer.apple.com/documentation/securityinterface/sfauthorizationpluginview/firstresponder() The longer story: I made my view class inherit SFAuthorizationPluginView. The API is preconcurrency (but not marked as preconcurrency) I started using concurrency in my plugin to retrieve data over XPC. (https://developer.apple.com/documentation/xpc/xpcsession + https://developer.apple.com/documentation/swift/withcheckedthrowingcontinuation(isolation:function:_:)) Once I retrieve the data over XPC, I need to post it on GUI, hence I've set my view class as @MainActor in order to do the thread switch. Swift compiler keeps complaining: override func firstResponder() -&gt; NSResponder? { return usernameField } "Main actor-isolated property 'usernameField' can not be referenced from a nonisolated context; this is an error in the Swift 6 language mode" override func firstResponder() -&gt; NSResponder? { MainActor.assumeIsolated { return usernameField } } "Sending 'self' risks causing data races; this is an error in the Swift 6 language mode" I think fundamentally, the API is forcing me to give away a @MainActor variable through a nonisolated function, and there is no way to shut up the compiler. I've tried @preconcurrency and it has no effect as far as I can tell. I've also tried marking the function explicitly as nonisolated. The rest of the API are less problematic, but returning a GUI variable is exceptionally difficult.
2
0
640
Jul ’25
Module compiled with Swift 6.0.3 cannot be imported by the Swift 6.1 compiler
Module compiled with Swift 6.0.3 cannot be imported by the Swift 6.1 compiler: /private/var/tmp/_bazel_xx/8b7c61ad484d9da1bf94a11f12ae6ffd/rules_xcodeproj.noindex/build_output_base/execroot/main/CustomModules/BIYThred/CocoaLumberjack/framework/CocoaLumberjack.framework/Modules/CocoaLumberjack.swiftmodule/arm64-apple-ios.swiftmodule
1
0
690
Jul ’25
Error about "swift for windows" at windows11
谁能告诉我为什么? “[正在运行] swift ”d:\vscode object\swift object\ceshi.swift” JIT 会话错误:未找到符号:[ $ss 27_allocateUninitializedArrayySayxG_BptBwlFyp_Tg5 ] 未能具体化符号: { (main, { main, $sSa 12_endMutationyyF, $ss 5print_9separator10terminatoryypd_S2StFfA0_, $ss 5print_9separator10terminatoryypd_S2StFfA1_, $ss 27_finalizeUninitializedArrayySayxGABnlF }) } [完成] 在 0.47 秒内退出并带有 code=4294967295” 当“Swift for Windows”在 VSCode for Windows 上运行时。 路径为 true,“Package-swift-lsp: Path”为 true。 谁能告诉我为什么?
1
0
812
Jul ’25
AsyncStream does not cancel inner Task
AsyncStream { continuation in Task { let response = await getResponse() continuation.yield(response) continuation.finish() } } In this WWDC video https://developer.apple.com/videos/play/wwdc2025/231/ at 8:20 the presenter mentions that if the "Task gets cancelled, the Task inside the function will automatically get cancelled too". The documentation does not mention anything like this. From my own testing on iOS 18.5, this is not true.
2
0
603
Jul ’25
Execute Swift scripts dynamically in iOS
I have a transformation function that takes in data, executes some instructions, and returns an output. This function is dynamic and not shipped with the binary. Currently, I’m executing it using JavaScriptCore.JSContext, which works well, but the function itself is written in JavaScript. Is there a way to achieve something similar using Swift – such as executing a dynamic Swift script, either directly or through other means? I know this is possible on macOS, but I’m not sure about iOS. I’ve also heard that extensions might open up some possibilities here. Any insights or alternative approaches would be appreciated.
4
0
315
Jul ’25
Load bundle resources in UI Tests
I want to load images from my bundle, which works fine when running the main app. However this does not work when running UI Tests. I read that the test bundle is not the main bundle when running tests. I try loading the bundle via this snippet: let bundle = Bundle(for: Frames_HoerspielUITests.self) This is my test class wrapped these the canImport statements so it can be added to the main app target and used for getting the correct bundle: #if canImport(XCTest) import XCTest final class Frames_HoerspielUITests: XCTestCase { override func setUpWithError() throws { continueAfterFailure = false } override func tearDownWithError() throws { } @MainActor func testExample() throws { let app = XCUIApplication() app.launch() } @MainActor func testLaunchPerformance() throws { measure(metrics: [XCTApplicationLaunchMetric()]) { XCUIApplication().launch() } } } #else final class Frames_HoerspielUITests { } #endif However while this works when running the main app, it still fails in the UI tests. It is a SwiftUI only app. and I can't add the images to the asset catalog because they are referenced from another location. Any ideas? Thank you
1
0
277
Jul ’25
Modifying an associated value of an existing enum instance
Hi, I would like to modify an associated value of an existing enum instance of the the following enum: enum FilterItem: Equatable, Hashable { case work(isSelected: Bool) ... var filterName: String { switch self { case .work: return "Work" ... } } var isSelected: Bool { switch self { case .work(let isSelected): return isSelected ... } } I want to be able to switch on the FilterItem type and then to be able to modify the isSelected property of the instance like: let itemToChange: FilterItem switch item { case .work(let isSelected): itemToChange.isSelected = !isSelected I know the above code doesn't compile, but I was wondering if there was a way I could modify my enum instance without creating a totally new enum instance.
5
0
366
Jul ’25
Swapping the `objectAtIndex:` method of `__NSArrayM` using `method_exchangeImplementations` will lead to continuous memory growth.
After swapping the -objectAtIndex: method using method_exchangeImplementations, it will cause continuous memory growth. Connect the iPhone and run the provided project. Continuously tap the iPhone screen. Observe Memory; it will keep growing. Sample code
2
0
317
Jul ’25
Swift OpenAPI Generator Error
PLATFORM AND VERSION iOS Development environment: Xcode 26, macOS 26 Run-time configuration: iOS 18 and up DESCRIPTION OF PROBLEM I am on the beta version of os 26 for both Xcode and macOS. When I try to run my project, which has the Swift OpenAPI Generator from apple, it gives the error "unsupported configuration: the aggregate target 'OpenAPIGenerator' has package dependencies, but targets that build for different platforms depend on it" STEPS TO REPRODUCE Install macOS 26 and Xcode 26 and try running an iOS app built for iOS 18.0 and up wit the OpenAPIGenerator package on a physical iPhone running iOS 26
1
0
343
Jul ’25
Tuple Comparision
I was trying to evaulate let myTuple = ("blue", false) let otherTuple = ("blue", true) if myTuple &lt; otherTuple { print("yes it evaluates") } Ans I got /tmp/S9jAk7P7KW/main.swift:5:12: error: binary operator '&lt;' cannot be applied to two '(String, Bool)' operands if myTuple &lt; otherTuple { My question is why there is no compile time issue in first place where the declaration is let myTuple = ("blue", false) ~~~~~~ something like above
2
0
441
Jul ’25
Crash in libswiftCore with swift::RefCounts
I'm seeing somewhat regular crash reports from my app which appear to be deep in the Swift libraries. They're happening in the same spot, so I'm apt to believe something is likely getting deallocated behind the scenes - but I don't really know how to guard against it. Here's the specific crash thread: 0 libsystem_kernel.dylib 0x00000001d51261dc __pthread_kill + 8 (:-1) 1 libsystem_pthread.dylib 0x000000020eaa8b40 pthread_kill + 268 (pthread.c:1721) 2 libsystem_c.dylib 0x000000018c5592d0 abort + 124 (abort.c:122) 3 libsystem_malloc.dylib 0x0000000194d14cfc malloc_vreport + 892 (malloc_printf.c:251) 4 libsystem_malloc.dylib 0x0000000194d14974 malloc_report + 64 (malloc_printf.c:290) 5 libsystem_malloc.dylib 0x0000000194d0e8b4 ___BUG_IN_CLIENT_OF_LIBMALLOC_POINTER_BEING_FREED_WAS_NOT_ALLOCATED + 32 (malloc_common.c:227) 6 Foundation 0x0000000183229f40 __DataStorage.__deallocating_deinit + 104 (Data.swift:563) 7 libswiftCore.dylib 0x0000000182f556c8 _swift_release_dealloc + 56 (HeapObject.cpp:847) 8 libswiftCore.dylib 0x0000000182f5663c bool swift::RefCounts&lt;swift::RefCountBitsT&lt;(swift::RefCountInlinedness)1&gt;&gt;::doDecrementSlow&lt;(swift::PerformDeinit)1&gt;(swift::RefCountBitsT&lt;(swift::RefCountInlinedness)1&gt;, unsigned int) + 152 (RefCount.h:1052) 9 TAKAware 0x000000010240c688 StreamParser.parseXml(dataStream:) + 1028 (StreamParser.swift:0) 10 TAKAware 0x000000010240cdb4 StreamParser.processXml(dataStream:forceArchive:) + 16 (StreamParser.swift:85) 11 TAKAware 0x000000010240cdb4 StreamParser.parseCoTStream(dataStream:forceArchive:) + 360 (StreamParser.swift:108) 12 TAKAware 0x000000010230ac3c closure #1 in UDPMessage.connect() + 252 (UDPMessage.swift:68) 13 Network 0x000000018506b68c closure #1 in NWConnectionGroup.setReceiveHandler(maximumMessageSize:rejectOversizedMessages:handler:) + 200 (NWConnectionGroup.swift:458) 14 Network 0x000000018506b720 thunk for @escaping @callee_guaranteed (@guaranteed OS_dispatch_data?, @guaranteed OS_nw_content_context, @unowned Bool) -&gt; () + 92 (&lt;compiler-generated&gt;:0) 15 Network 0x0000000185185df8 invocation function for block in nw_connection_group_handle_incoming_packet(NWConcrete_nw_connection_group*, NSObject&lt;OS_nw_endpoint&gt;*, NSObject&lt;OS_nw_endpoint&gt;*, NSObject&lt;OS_nw_interface&gt;*, NSObje... + 112 (connection_group.cpp:1075) 16 libdispatch.dylib 0x000000018c4ad2b8 _dispatch_block_async_invoke2 + 148 (queue.c:574) 17 libdispatch.dylib 0x000000018c4b7584 _dispatch_client_callout + 16 (client_callout.mm:85) 18 libdispatch.dylib 0x000000018c4d325c _dispatch_queue_override_invoke.cold.3 + 32 (queue.c:5106) 19 libdispatch.dylib 0x000000018c4a21f8 _dispatch_queue_override_invoke + 848 (queue.c:5106) 20 libdispatch.dylib 0x000000018c4afdb0 _dispatch_root_queue_drain + 364 (queue.c:7342) 21 libdispatch.dylib 0x000000018c4b054c _dispatch_worker_thread2 + 156 (queue.c:7410) 22 libsystem_pthread.dylib 0x000000020eaa5624 _pthread_wqthread + 232 (pthread.c:2709) 23 libsystem_pthread.dylib 0x000000020eaa29f8 start_wqthread + 8 (:-1) Basically we're receiving a message via UDP that is an XML packet. We're parsing that packet using what I think it pretty straightforward code that looks like this: func parseXml(dataStream: Data?) -&gt; Array&lt;String&gt; { var events: [String] = [] guard let data = dataStream else { return events } currentDataStream.append(data) var str = String(decoding: currentDataStream, as: UTF8.self) while str.contains(StreamParser.STREAM_DELIMTER) { let splitEvent = str.split(separator: StreamParser.STREAM_DELIMTER, maxSplits: 1) let cotEvent = splitEvent.first! var restOfString = "" if splitEvent.count &gt; 1 { restOfString = String(splitEvent.last!) } events.append("\(cotEvent)\(StreamParser.STREAM_DELIMTER)") str = restOfString } currentDataStream = Data(str.utf8) return events } the intention is that the message may be broken across multiple packets, so we build them up here. Is there anything I can do to guard against these crashes?
5
0
177
Jul ’25
Swift/C++ interoperability issue in std::string
In scope of one of our project we've faced an issue with constant crashes when integrating C++ library in Swift code using Swift/C++ interoperability. Investigating the root causes of the issue we've discovered that with new version of Swift bug was introduced. Long story short: for strings bigger than 27 symbols memory is feed incorrectly that causes the crashes. By creating this post I wanted to draw community's attention to the problem and promote it to be solved quicker as for now it is not addressed.
1
0
514
Jul ’25
Bridging Headers is unsupported or Module compiled with Swift 5.5.1 cannot be imported by the Swift 5.6 complier
Hello guys! I faced a problem with building... My device suddenly updated to iOS 15.4.1, my Xcode was 13.2 and I had to update it to the latest version (13.3.1) to build the app. After the update, I had a few problems which were successfully solved but one of them stopped me for a few hours. The problem is with Bridging Headers or Swift Compiler, I really don't know what I did badly, and what causes problems. On several forums I often read that is important to set: Build Settings &gt; Build Options &gt; Build Libraries for Distribution But in any case it doesn't work, on yes: error: using bridging headers with module interfaces is unsupported on no: (line with import framework SWXMLHash) /Users/blablabla/SSLModel.swift:9:8: error: module compiled with Swift 5.5.1 cannot be imported by the Swift 5.6 compiler: /Users/blablabla2/Build/Products/Debug-iphoneos/SWXMLHash.framework/Modules/SWXMLHash.swiftmodule/arm64-apple-ios.swiftmodule import SWXMLHash It will be important that I use Carthage. What should I do? Clone all 10 frameworks that I use and re-build them with a new Xcode which includes compiler 5.6? That may be a bad solution... Any answers on similar topics don't help..
3
0
2.9k
Jul ’25
Exposing Objective-C API to Swift inside a Framework (Private Framework API)
My framework has private Objective-C API that is only used within the framework. It should not be exposed in the public interface (so it shouldn't be imported in the umbrella header). To expose this API to Swift that's within the framework only the documentation seems to indicate that this needs to be imported in the umbrella header? Import Code Within a Framework Target To use the Objective-C declarations in files in the same framework target as your Swift code, configure an umbrella header as follows: 1.Under Build Settings, in Packaging, make sure the Defines Module setting for the framework target is set to Yes. 2.In the umbrella header, import every Objective-C header you want to expose to Swift. Swift sees every header you expose publicly in your umbrella header. The contents of the Objective-C files in that framework are automatically available from any Swift file within that framework target, with no import statements. Use classes and other declarations from your Objective-C code with the same Swift syntax you use for system classes. I would imagine that there must be a way to do this?
0
0
265
Jul ’25