Post

Replies

Boosts

Views

Activity

Perform action once UIActivityViewController has completed item action
I use UIActivityViewController to airDrop pdfFile (pdfURL) from iPhone to iMac. Works well, file is airDropped. let activityVC = UIActivityViewController(activityItems: [pdfURL], applicationActivities: nil) present(activityVC, animated: true, completion: nil) I want to customise it: limit services to AIrDrop and mail How can I exclude such services as WhatsApp, Notes… ? perform some action once the file has completed airDrop or once cancelled. I tried to implement with completionWithItemsHandler:         activityVC.completionWithItemsHandler = { (activity, success, items, error) in             print("Completed")         } This doesn't work, print is not executed. My ultimate goal is to close the activityVC automatically once action was completed, without need to tap close button. Should I define some content for applicationActivities ?
2
0
918
Jan ’22
How to constrain a tableView to safe area ?
Here is the set up: I try to set a constraint for the top of tableView relative to safe area. No way by control-drag from tableView to Safe area. But if i create such a constraint for another object (here, like upperView) and then edit the constraint in Inspector, I can replace UpperView by tableView ; and get my constraint set. What am I missing here ?
2
0
958
Feb ’22
ViewBuilder does not force View update
I use a ViewBuilder to generate the destination used in a NavigationSplitView (to select the detail View). This viewBuilder depends on a parameter (in fact 2, but I try to simplify). ViewBuilder is simple, just calls a View: @ViewBuilder func destination(object: SomeObject, name: String) -> some View { MyView(objToUse: object, nameToUse: name) } But this does not work. When I change the selection in the Master of the splitView, view is not updated (even though I've checked the content is updated. This si so simple that I started using directly MyView(objToUse: object, nameToUse: name) in the detail View. It did not work either. Now, here is the surprise: if I use a switch statement in the ViewBuilder, it works: Let's say we have: struct SomeContent: Hashable, Identifiable, Codable { var id = UUID() var name: String } struct Object : Hashable, Identifiable, Equatable, Codable { var id = UUID() var content: [SomeContent] = [] } So I define a func to get all the names func allNames(of object: SomeObject) -> [String] { var names : [String] = [] for o in object.content { names.append(o.name) } return names } And modify ViewBuilder as follows: it works @ViewBuilder func destination(object: SomeObject, name: String) -> some View { let names : [String] = allNames(of: object) switch name { case names[0]: MyView(objToUse: object, nameToUse: name) case names[1]: MyView(objToUse: object, nameToUse: name) case names[2]: MyView(objToUse: object, nameToUse: name) default: EmptyView() } It also works with nested if else if instead of a switch. What is it I am missing ?
2
0
912
Jan ’23
Dark mode switching modifies ObservedObject
This is a SwiftUI Mac App. There is an observable object with a published array class AllObjects : ObservableObject { @Published var theItems = [Item]() } In the View, observed with: @ObservedObject var allObjects : AllObjects Item class is : class Item: ObservableObject, Identifiable { let id = UUID() var placeNo = 1 // Other properties } When I switch dark / light mode within the app (with a toggle) @Environment(\.colorScheme) var colorScheme the ObservedObject allObjects is modified: array is emptied: allObjects.theItems is now an empty array. What could cause the change to theItems ? I have checked that the only func un which theItems is reset to [] is not called.
2
0
685
Apr ’23
Are storyboard and UIKit due to disappear ?
I read in Xcode 15.2 release notes that @IBDesignable and @Inspectable are deprecated and will disappear in a future release. After the abandon of WatchKit and its storyboard, replaced by SwiftUI, does it mean storyboards (and consequently UIKit) will progressively disappear, leaving developers alone with SwiftUI to design apps (IMHO, inadequate to design complex UI: for instance, I always struggle to position precisely objects for all devices sizes as we miss constraints manager in SwiftUI) ? For sure, IBDesignable is (was) whimsical, but a very useful tool to design sophisticated UI. Replacing by #Preview does not make it. I also understand that Xcode is a very complex piece of code and that maintaining and evolving some tools (as IBDesignable) requires effort. But isn't it what we expect from Apple ? To provide us with the best tools and keep on the promise of WYSIWYG environments, all along ? Is it only me or do others share this view ?
2
0
2.7k
Dec ’23
Inconsistencies between mail notification from forum and forum content
Is it only me ? I received recently a notification that an answer was "recommended by Apple", with a link to the post. But when going to the post, this recommendation (with small Apple icon) do not show. And the forum scores are not updated. This is not the first time I get problems with forum notifications. I filed a bug report: FB14172207
2
1
1k
Jul ’24
Immediate crash of Apple Watch simulator when typing a key
I get a crash in Apple Watch simulator (Series 9 45mm 18.0) as soon as the app launch if I type anything on external keyboard (just hitting command key for instance to capture a screenshot). Same crash on series 7 (45mm, OS 18.1) But app works normally when I use mouse to interact with the app on simulator. App does not crash on real device (Watch 4 OS 10.4.1). Nor does it crash on Series 6 simulator (44 mm OS 17.4). Here are the log I could collect (apparently, they contain sensitive language !!! so I attach as a file.: Attached logs
2
0
424
Mar ’25
URL passed as attachment to notification is deleted when notification is added
I create a notification with an image attachment: let center = UNUserNotificationCenter.current() center.delegate = self let content = UNMutableNotificationContent() // some more stuff… let paths = NSSearchPathForDirectoriesInDomains( FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) let documentsDirectory = paths[0] as NSString let fileExtPNG = "#" + "\(imageName)" + " photo.png" let fileNamePNG = documentsDirectory.appendingPathComponent(fileExtPNG) as String url = URL(fileURLWithPath: fileNamePNG) let attachment = try UNNotificationAttachment(identifier: "Image", url: url, options: nil) content.attachments = [attachment] I then add the request: let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: nil) center.removePendingNotificationRequests(withIdentifiers: [requestIdentifier]) center.add(request) {(error) in } Problem: when I later test (once notification has been registered), the file do not exist anymore at the url. I've commented out the add request to confirm. I have a work around, by creating a temporary copy of the file at the URL and pass it in the attachment. Then, everything works fine and the copy is deleted. But that's a bit bizarre. What am I missing here ?
2
0
368
Feb ’25
Using and expressing "case let" statements
After seveal years with Swift, I still find it hard to use the if case let or while case let, even worse with opotional pattern if case let x?.So, I would like to find an expression to "speak" case let more naturally.Presently, to be sure of what I do, I have to menatlly replace the if case by the full switch statement, with a single case and default ; pretty tedious.I thought of canMatch or canMatchUnwrap … with:So, following would readif case let x = y { // if canMatch x with yif case let x? = someOptional { // if canMatchUnwrap x with someOptionalwhile case let next? = node.next { // while canMatchUnwrap next with node.nextAm I the only one with such problem ? Have you found a better way ?
5
0
7.7k
Jun ’21
Height of safe area margin in iPhone 12 Pro Max
I have an image to fill the entire screen, even behind the notch. So I set the Top margin to safe area to -44. That works OH on all iPhones… except on iPhone 12 ProMax simulator. Here I get a few pixels uncovered at top. I had to change value to -48 to get everything OK. So question is: has "notch area" which defines safe area increased 4 pixels on iPhone 12 Pro max ? If so, is it a hardware change ?
1
0
4k
Jun ’21
Cannot activate Xcode Edit>Substitution menu
When editing a Swift file in Xcode 12.2, I wanted to change the quotes autocompletion. For this I looked at the Edit > Substitution menu and selected smartQuotes. From this point, the whole substitution menu is disabled, no way to enable back. Opened another file: same issue. Opened another older version of Xcode: the same. Opened Xcode 12.2 on another Mac: same thing How can I re-enable the menu ? Whilst typing this message, I tried again and the menu is once again reactivated ! I did nothing (at least intentionally). Was it some type of time out or time required to complete a task ? But did not return to normal on the other Mac. But now, 10 more minutes later, it is disabled once again… That's the type of surprise effect I do dislike in an app…
1
0
701
Dec ’20
Uppercased words are not spoken correctly
Using AVSpeechSynthesizer, I noticed that some works in UPPERCASe are not correctly spoken. SMALL is pronounced small but WIDTH is pronounced W-I-D-T-H I reproduced the problem in playground: let sentence = "Hello everyone. Two minutes to go. SMALL WIDTH." let synthesizer = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: sentence) utterance.voice = AVSpeechSynthesisVoice( 	language: "en-GB" ) utterance.rate = AVSpeechUtteranceDefaultSpeechRate * 1.05 synthesizer.speak(utterance) Is it the expected behaviour ?
1
0
1.2k
Mar ’21
Distribution of MacApp outside of Appstore for a demo version
I consider the following distribution scheme for some Mac App: distribute the commercial (paying) version on Appstore propose a free demo version (of course limited in some aspects) on a web site. This would of course be notarised. The reason is to avoid having several versions on the Appstore which could create some confusion. The 2 versions would have similar names and differ essentially in the size of data they can handle. Does anyone know if this is authorised by the Appstore Guidelines ? Or must I publish both on the AppStore ? Is there a risk my app being rejected as spam ?
1
0
591
Apr ’21
Sandbox - security scoped URL - MacOS
In a MacOS App: When I create a file (in a folder), I save a security bookmark for the file. if I ask user to authorise its folder (before creating the file in it), I can save its bookmark too, allowing to create other files in this folder. So, when I create a file and need to create a companion (eg, a Results file), I first ask access to the folder, then create the file and create the results file in the same folder (hence having sandbox authorisation). My understanding is that it is not possible to programmatically create and save the folder bookmark, after deriving its url from the file url, without requesting user to explicitly grant access (with NSOpen panel) ? Which would be very logical as it would deny the goal of security bookmarks. So, is user explicit authorisation required (logical but creates more complexity when user moves files in the Finder). Note: In fact don't really need it, as I save bookmark for every accessed file, but I would like to know.
1
0
802
Apr ’21