Post

Replies

Boosts

Views

Activity

Passing compatible primitive types as reference in cpp-swift interop
I have an xcode project which has both cpp and swift code. In one of my usecase I am passing primitive type variables from swift to cpp by reference( primitives types list here as per the new cpp-swift interop documentation) swift code: // primitive check code:Bool var x : Bool = true // When we are passing a variable as a Reference, we need to use explicitly use'&' student.PassBoolAsReferenceType (&x) // interop call to cpp code print (x) Cpp code: void Student::PassBoolAsReferenceType(bool &pValue) noexcept { std::cout << pValue << std::endl; pValue = false; } The above code fails during compilation with no clear error message "Command SwiftCompile failed with a nonzero exit code" However, all the other primitive types that I tested worked for the above code like Int, Float, Double etc. Only the Bool interop fails. Can someone explain why is it not possible for bool? I m using the new interop introduced in swift 5.9.
1
0
97
1d
Identifying UIKit Api's failure
I have a UIKit application and it contains multiple UI components like UIWindow, UIView, UIButton, etc. I wanted to perform error handling for different OS calls in my application. For example, when creating a UIImage using init(named:) initialiser, the documentation clearly states that if the UIImage object cannot be created then the initialiser returns nil value. However, there are other UI components like UIButton (or like UIView), which when created using init(frame:) initialiser, the documentation does not mention for any return value. I wanted to know how to identify If the UIButton initialisation has failed? How is it that apple recommends should we handle these api's, If they fail to create a button. suppose If there is a case where it fails due to insufficient memory. Or is it that apple guarantees the Api's never fail?Is there some exception that is throw? I wanted somewhat detailed answer to these questions.
2
0
120
5d
Error Handling for Widget APIs in iOS that neither raise any exception nor return any value?
I was looking out for the error handling for rendering the Widgets(like UIButton, UIVIew etc) on the screen in iOS. I am painting the screen programmatically using swift. Considering a simple Widget(like for say UIButton) when we try to create using its initializer and set some properties like 'setTitle' . These functions neither return any value upon success/failure nor in documentation they have mentioned about any exceptions which would be raised upon failure. https://developer.apple.com/documentation/uikit/uibutton/settitle(_:for:) So, how to do error handling here in this scenarios, in case the apis fail to due some reason, like memory issue? There must be some scenarios for these api failure.
2
0
141
1w
Help with SwiftUI and UIKit Interjection
Hi, need some help with an iOS application we are trying to make future safe. Basically, we know that our app would require SwiftUI so the app is made in that framework, however we require some important elements that are available only in UIKit, so we've made a bridge that allows us to pass UIKit views to SwiftUI to display them. So most of the app actually has UI made in UIKit, however, we now need to use the Charts framework present in SwiftUI, we've used SwiftUI buttons in our UIKit before by passing them through a HostingController (Passing SwiftUI buttons to UIKit to use). And we are currently considering to the same for SwiftUI Charts. Just to recap, it's a SwiftUI iOS app, that is mostly made in UIKit (through a bridge) but also has other SwiftUI elements injected into it. What we want to know that, is this the best way to do this? Or is there a better way to have UIKit and SwiftUI work more comfortably with eachother. The reason for such looping around is also because we interoping our C++ code to Swift for making this application, since we are making it for many other platforms and the business logic is in C++. Let me know if there are better ways to go about this!
1
0
138
2w
Modifying SwiftUI view added as a subview to UIKit View
I have a UIKit application and I have some swiftUI views(like button widget etc) that I m using in this application which are added as a subview using UIHostingController. I wanted to understand what is the right way as per the apple recommendation on how to perform some updates on these views, since the UIKit and SwiftUI have a different way of operating. In a pure swiftUI application we use the @State variables which when modified the view are re-rendered. However, in an UIKit application we can directly modify the widget property like color or font from the object. So, my question is should I get the hostingController object from the swiftUI view and then perform any update on that UIKit view. Is this the right way? If not, what is the correct way? can someone provide a detailed explanation?
0
0
127
2w
Storing SwiftUI Views to operate on it
I am creating a UIKit application but that contains SwiftUI Views embedded using the hostingcontroller. I have a particular approach for it..but it requires instantiating a swiftUI view, creating a hostingcontroller object from it and storing a reference to it. So that later If I wanted to update the view, I can simply get the reference back and update the swiftUI view using it. I wanted to understand what does apple recommends on this. Can we store a swiftUI instance? Does it cause any issue or it is okay to do so?
0
0
197
Nov ’24
Unable to update NSProgressIndicator for the dock Icon
I have created a progress indicator to simulate some progressing download task in the dock icon. However, I can see the progress bar appearing in the dock icon but it is not getting updated when I invoked the updateProgress() method. Ideally it should have updated it, and I m not able to figure out the reason? I have creating the same NSProgressIndicator on an NSWindow and it works to update the progress bar with the same code. Anything that I m missing to understand here? Below is the code I m using: class AppDelegate: NSObject, NSApplicationDelegate { var progressIndicator: NSProgressIndicator! let dockTile = NSApp.dockTile func applicationWillFinishLaunching(_ notification: Notification) { // Step 1: Create a progress bar (NSProgressIndicator) progressIndicator = NSProgressIndicator(frame: NSRect(x: 10, y: 10, width: 100, height: 20)) progressIndicator.isIndeterminate = false progressIndicator.minValue = 0.0 progressIndicator.maxValue = 100.0 progressIndicator.doubleValue = 0.0 progressIndicator.style = .bar dockTile.contentView = progressIndicator dockTile.display() //// Update the progress bar for demonstration DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.updateProgress(50) } } func updateProgress(_ value: Double) { progressIndicator.doubleValue = value NSApp.dockTile.display() } }
0
0
265
Oct ’24
NSClickGestureRecognizer not working to invoked the registered event method
I have created a NSView inside the NSWindow. I m trying to identify when the view gets clicked by the user. For this I m using NSClickGestureRecognizer, but the registered method is not getting invoked. I have tried adding this for other widgets like button but it does not work either. Am I missing something? class SelectionList :NSObject, NSTextFieldDelegate{ let containerView = NSView() func createSelectionList (pWindow: NSWindow) { // created container View ... let clickRecognizer = NSClickGestureRecognizer() clickRecognizer.target = self clickRecognizer.buttonMask = 0x2 // right button clickRecognizer.numberOfClicksRequired = 1 clickRecognizer.action = #selector(ClickGestured) containerView .addGestureRecognizer(clickRecognizer) } @objc func clickRecognizer() { print("clicked") } }
0
0
241
Sep ’24
"App not responding" in the dock menu
I have a bundled macOS application. This is a non-interactive application where I m performing some task on the worker thread while the main thread waits for this task to be completed. Sometimes this task can be time consuming. I have observed that when I run the application using the bundle( like double click or open command) I can see the OS marking my application as not responding( this is evident as the app icon toggles in the dock and then it states not responding). Although If I run the unix executable in the bundle, the app runs and I do not see the not responding status anywhere. I wanted to understand If this is happening because my main thread is in a waiting state? If yes, what could I do to resolve it because my application logic demands the main thread to wait for the worker thread to complete its task. Is there some way to use some event loop like GCD? Note: I cannot use the delegates(Appkit) event loop because my application will be run in non-GUI context.
5
0
595
Jul ’24
Using bundled applications(.app file) as daemon/Agent
I have a .app file that I want to run as a daemon. Now there are two ways of running .app as a daemon/agent in macOS. using .app file : I can specify this in the daemon plist as: <key>ProgramArguments</key> <array> <string>/usr/bin/open</string> <string>/Applications/myApp.app</string> </array> using unix exe within .app file <key>ProgramArguments</key> <array> <string>myApp.app/Content/MacOS/MyApp</string> </array> Basically I wanted to know what is the Apple recommendation on how we should be creating daemon plist. For point 2, is it appropriate to use the unix executable within bundle?Will it not cause any issue in the running application? Is will be helpful if there is some apple documentation to support this.
1
0
413
Jul ’24
representation error in swift generated header
I have a public swift function with the below declaration : public func InternalMain (_ pNumOfArgs : Int32, _ pCmdlineArgs : UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>) -> Int32 {..} I need this function as public because I need to invoke in from a different library. But the above declaration produces an error in my generated swift header i.e '-swift.h' file because 'UnsafeMutablePointer<UnsafeMutablePointer?>' type cannot be represented in the swift generated header. Can someone help how do I get past this. This is a class independent function and I tried using the '@nonobj' to prevent this from getting in the generated header but it still gives an error.
2
0
674
Jun ’24
'open' command in macOS fails to launch .app file in non GUI environment
I have a bundled application(.app file) in macOS which is a non-interactive application. This app does not link to any GUI frameworks and I am able to launch it using the 'open' command in a normal GUI login session. However, when I perform ssh login to that user and then If I try to launch the application, it fails to launch. I assume that this is happening because my ssh session is a non-GUI session, and 'open' command is due to some reason failing to run in a non-GUI environment, but I m not sure. Can someone help me understand why is this happening?
1
0
395
May ’24
How to identify If my executable is launched as User Agent in macOS
I have an executable in macOS that I m launching as a User Agent. The same executable can be launched in multiple ways like either user can directly click the exe to launch it, or user can launch it from the terminal using ./ etc. One similar way is when the user launches the exe as a User Agent(i.e daemon in user session). In this scenarios, I want to identify in my exe If my user has launched it as agent to perform certain task. I wanted to know how can I accurately determine this? I have tried figuring out If there is some unique session that agents operate in, but I could not find anything. Can someone help here? Is this even possible?
1
0
484
May ’24