I have macOS application and I want to provide an action for it in the 'Shortcuts' app QuickAction list. I was using InApp handling to present my intent created in the intent.intentdefinition file as action in the shortcuts app and it was working.
However, this action perform a very lightweight task so I intent to have the action implemented as an extension in my xcode project.
According to my minimum deployment(i.e macOS 11.0) I found that 'Intents Extension' could be used.
I have added the 'Intents extension' target to my main application and created an intent using the intent.intentdefinition file. However, my intent does not appear in the shortcuts app. I have verified it multiple time to ensure I am not missing anything, but still the intent is not present in the shortcuts app action.
I wanted to be know, Is this even possible? cause this apple documentation only mentions about iOS and watchOS app. It also does not mention If our custom intent(created using Intents extension) in the intents extension can be exposed to the shortcuts app.
For macOS 13.0+, I have used the 'AppIntents extension' and I m able to achieve the same. So, I suppose the same should be possible using the 'Intents extension'
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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?
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?
Is there some notification that apple provides that I can register to, and get notified whenever there is a 'battery low' state?
I want to perform certain task in my application for low battery.
Is there some way to identify this?
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.
I wanted to create a bundled macOS application that can be run in background. This application should also be capable of running in a non-gui environment.
How should I create the application with the only condition that it should be bundled and can be launched using multiple ways like double click the bundle app or launching as a daemon using the unix executable?
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?
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!
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.
I understand two key concepts from desktop platforms:
Screen Mirroring – The same content is displayed on both the primary and external screens.
Screen Extension – The external display shows different content that complements what's on the main screen.
My question pertains to the second point: Is it possible to extend the display on iOS and iPadOS devices?
I'm referring to this Apple documentation, which explains how to extend content from an iOS/iPadOS device to an external display.
I tested this in a sample iOS Xcode project. In the iOS Simulator, I was able to detect an "external display" and present a separate UIWindow on it. However, when I tried the same on a real device (iPhone 15 connected to a MacBook Pro via cable), the external display connection was not detected.
I’d like to confirm whether screen extension is possible on a real iOS device. From my research, it appears that extension is only supported on iPadOS via Stage Manager, but I want to verify if there’s any way to achieve this on an iPhone. If so, are there any known apps that currently utilize extended display functionality on iOS?
If extension is not possible on iOS, what does the documentation mentions iOS?
In UIKit, certain events like a button tap can be simulated using:
button.sendActions(for: .touchUpInside)
This allows us to trigger the button’s action programmatically.
However, in SwiftUI, there is no direct equivalent of sendActions(for:) for views like Button. What is the recommended approach to programmatically simulate a SwiftUI button tap and trigger its action?
Is there an alternative mechanism to achieve this(and for other events under UIControl.event) , especially in scenarios where we want to test interactions or trigger actions without direct user input?
In a UIKit application, removing a view from the hierarchy is straightforward—we simply call myView.removeFromSuperview(). This not only removes myView from the UI but also deallocates any associated memory.
Now that I'm transitioning to SwiftUI, I'm struggling to understand the recommended way to remove a view from the hierarchy, given SwiftUI's declarative nature.
I understand that in SwiftUI, we declare everything that should be displayed. However, once a view is rendered, what is the correct way to remove it? Should all UI elements be conditionally controlled to determine whether they appear or not?
Below is an example of how I’m currently handling this, but it doesn’t feel like the right approach for dynamically removing a view at runtime.
Can someone guide me on the best way to remove views in SwiftUI?
struct ContentView: View {
@State private var isVisible = true
var body: some View {
VStack {
if isVisible { // set this to false to remove TextView?
Text("Hello, SwiftUI!")
.padding()
}
Button("Toggle View") {
...
}
}
}
}
I'm working on an iOS app that requires an @mention system in a UITextView, similar to those in apps like Twitter or Slack. Specifically, I need to:
Detect @ Symbol and Show Dropdown: When the user types "@", display a dropdown (UITableView or similar) below the cursor with a list of mentionable users, filtered as the user types.
Handle Selection: Insert the selected username as a styled mention (e.g., blue text).
Smart Backspace Behavior: Ensure backspace deletes an entire mention as a single unit when the cursor is at its end, and cancels the mention process if "@" is deleted.
I've implemented a solution using UITextViewDelegate textViewDidChange(_:) to detect "@", a UITableView for the dropdown, and NSAttributedString for styling mentions. For smart backspace, I track mention ranges and handle deletions accordingly. However, I’d like to know:
What is Apple’s recommended approach for implementing this behavior?
Are there any UIKit APIs that simplify this, for proving this experience like smart backspace or custom text interactions?
I’m using Swift/UIKit. Any insights, sample code, or WWDC sessions you’d recommend would be greatly appreciated!
Edit: I am adding the ViewController file to demonstrate the approach that I m using.
import UIKit
// MARK: - Dummy user model
struct MentionUser {
let id: String
let username: String
}
class ViewController: UIViewController, UITextViewDelegate, UITableViewDelegate, UITableViewDataSource {
// MARK: - UI Elements
private let textView = UITextView()
private let mentionTableView = UITableView()
// MARK: - Data
private var allUsers: [MentionUser] = [...]
private var filteredUsers: [MentionUser] = []
private var currentMentionRange: NSRange?
// MARK: - View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
setupTextView() // to setup the UI
setupDropdown() // to setup the UI
}
// MARK: - UITextViewDelegate
func textViewDidChange(_ textView: UITextView) {
let cursorPosition = textView.selectedRange.location
let text = (textView.text as NSString).substring(to: cursorPosition)
if let atRange = text.range(of: "@[a-zA-Z0-9_]*$", options: .regularExpression) {
let nsRange = NSRange(atRange, in: text)
let query = (text as NSString).substring(with: nsRange).dropFirst()
currentMentionRange = nsRange
filteredUsers = allUsers.filter {
$0.username.lowercased().hasPrefix(query.lowercased())
}
mentionTableView.reloadData()
showMentionDropdown()
} else {
hideMentionDropdown()
currentMentionRange = nil
}
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text.isEmpty, let attributedText = textView.attributedText {
if range.location == 0 { return true }
let attr = attributedText.attributes(at: range.location - 1, effectiveRange: nil)
if let _ = attr[.mentionUserId] {
let fullRange = (attributedText.string as NSString).rangeOfMentionAt(location: range.location - 1)
let mutable = NSMutableAttributedString(attributedString: attributedText)
mutable.deleteCharacters(in: fullRange)
textView.attributedText = mutable
textView.selectedRange = NSRange(location: fullRange.location, length: 0)
textView.typingAttributes = [
.font: textView.font ?? UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.label
]
return false
}
}
return true
}
// MARK: - Dropdown Visibility
private func showMentionDropdown() {
guard let selectedTextRange = textView.selectedTextRange else { return }
mentionTableView.isHidden = false
}
private func hideMentionDropdown() {
mentionTableView.isHidden = true
}
// MARK: - UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filteredUsers.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "@\(filteredUsers[indexPath.row].username)"
return cell
}
// MARK: - UITableViewDelegate
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
insertMention(filteredUsers[indexPath.row])
}
// MARK: - Mention Insertion
private func insertMention(_ user: MentionUser) {
guard let range = currentMentionRange else { return }
let mentionText = "\(user.username)"
let mentionAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.systemBlue,
.mentionUserId: user.id
]
let mentionAttrString = NSAttributedString(string: mentionText, attributes: mentionAttributes)
let mutable = NSMutableAttributedString(attributedString: textView.attributedText)
mutable.replaceCharacters(in: range, with: mentionAttrString)
let spaceAttr = NSAttributedString(string: " ", attributes: textView.typingAttributes)
mutable.insert(spaceAttr, at: range.location + mentionText.count)
textView.attributedText = mutable
textView.selectedRange = NSRange(location: range.location + mentionText.count + 1, length: 0)
textView.typingAttributes = [
.font: textView.font ?? UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.label
]
hideMentionDropdown()
}
}
// MARK: - Custom Attributed Key
extension NSAttributedString.Key {
static let mentionUserId = NSAttributedString.Key("mentionUserId")
}
I’m working with UIButton and I’d like to register multiple UIControl.Events (e.g. .touchUpInside, .touchDown, .touchCancel, .primaryActionTriggered) using the same selector.
For example:
button.addTarget(self,
action: #selector(handleButtonEvent(_:forEvent:)),
for: [.touchUpInside, .touchDown, .touchCancel, .primaryActionTriggered])
@objc func handleButtonEvent(_ sender: UIButton, forEvent event: UIEvent) {
// How do I tell which UIControl.Event triggered this?
}
From my understanding:
If I use the single-parameter version (@objc func handleButtonEvent(_ sender: UIButton)), I can’t distinguish which event fired.
If I use the two-parameter version with UIEvent, I can inspect touch.phase or event.type, but that feels indirect.
Questions:
Is there a recommended way to directly know which UIControl.Event caused the selector to fire?
Is sharing a single selector across multiple control events considered a good practice, or is it more common to register separate selectors per event?
Would appreciate guidance on what Apple recommends here.
I am building a centralized event handling system for UIKit controls and gesture recognizers. My current approach registers events using static methods inside a handler class, like this:
internal class TWOSInternalCommonEventKerneliOS {
internal static func RegisterTouchUpInside(_ pWidget: UIControl) -> Void {
pWidget.addTarget(
TWOSInternalCommonEventKerneliOS.self,
action: #selector(TWOSInternalCommonEventKerneliOS.WidgetTouchUpInsideListener(_:)),
for: .touchUpInside
)
}
@objc
internal static func WidgetTouchUpInsideListener(_ pWidget: UIView) -> Void {
print("WidgetTouchUpInside")
}
}
This works in my testing because the methods are marked @objc and static, but I couldn’t find Apple documentation explicitly confirming whether using ClassName.self (instead of an object instance) is officially supported.
Questions:
Is this approach (passing ClassName.self as the target) recommended or officially supported by UIKit?
If not, what is the safer alternative to achieve a similar pattern, where event registration can remain in static methods but still follow UIKit conventions?
Would using a shared singleton instance as the target (e.g., TWOSInternalCommonEventKerneliOS.shared) be the correct approach, or is there a better pattern?
Looking for official guidance to avoid undefined behavior in production.