Post

Replies

Boosts

Views

Activity

How to solve this NSKeyedArchiver warning
I get several warnings in log: *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSNumber' (0x204cdbeb8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{( "'NSArray' (0x204cd5598) [/System/Library/Frameworks/CoreFoundation.framework]" )}'. This will be disallowed in the future. I am not sure how to understand it: I have removed every NSNumber.self in the allowed lists for decode. To no avail, still get the avalanche of warnings. What is the key NS.objects about ? What may allowed classes set: '{( "'NSArray' be referring to ? An inclusion of NSArray.self in a list for decode ? The type of a property in a class ?
4
0
275
2w
Can we decode twice in the same session with unarchiver?
In a class, I call the following (edited to simplify, but it matches the real case). If I do this: func getData() -> someClass? { _ = someURL.startAccessingSecurityScopedResource() if let data = NSData(contentsOf: someURL as URL) { do { let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data as Data) print((unarchiver.decodeObject(of: [NSArray.self, someClass.self /* and few others*/], forKey: oneKey) as? someClass)?.aProperty) if let result = unarchiver.decodeObject(of: [NSArray.self, someClass.self /* same other types*/], forKey: oneKey) as? someClass { unarchiver.finishDecoding() print("unarchived success") return result } else { unarchiver.finishDecoding() print("unarchiving failed") return someClass() } } catch { return nil } } I get a failure on log : unarchiving failed But if I comment out the print(unarchiver.decodeObject) - line 8, it works and I get unarchived success // print((unarchiver.decodeObject(of: [NSArray.self, someClass.self /* and few others*/], forKey: oneKey) as? someClass)?.aProperty) However, when I do exactly the same for another class (I've compared line by line to be sure), it works even with the print statement. What could be happening here ?
3
0
108
1w
Setting the highlight colour of a selected cell in NSTableView
That's a question for Mac app (Cocoa). I want to change the standard highlighting. I thought to use tableView.selectionHighlightStyle. But there are only 2 values: .none and .regular. Cannot find how to define a custom one. So I tried a workaround: set tableView.selectionHighlightStyle to .none func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { tableView.selectionHighlightStyle = .none keep track of previousSelection Then, in tableViewSelectionDidChange reset for previousSelection func tableViewSelectionDidChange(_ notification: Notification) { } if previousSelection >= 0 { let cellView = theTableView.rowView(atRow: previousSelection, makeIfNecessary: false) cellView?.layer?.backgroundColor = .clear } set for the selection to a custom color let cellView = theTableView.rowView(atRow: row, makeIfNecessary: false) cellView?.layer?.backgroundColor = CGColor(red: 0, green: 0, blue: 1, alpha: 0.4) previousSelection = row Result is disappointing : Even though tableView.selectionHighlightStyle is set to .none, it does overlays the cellView?.layer Is there a way to directly change the color for selection ?
4
0
146
1w
Inserting an NSView (Cocoa) in NSWindowController Views hierarchy
I have an NSWindowController with several IBOutlets created in storyboard. I want to add an NSView and fill it with some color. I need to place it at a specific position in views hierarchy. I have tried 2 ways, no one succeeds. First. include a custom view in storyboard connect to an IBOutlet in an init of controller, set the layer for the view Result: crash Second build programmatically Result: I do not find where to put this code in the controller code That's basic Cocoa, but way more painful than iOS.
Topic: UI Frameworks SubTopic: AppKit Tags:
3
0
197
1w
Getting back from Splitview
In this app, I have: a VC as entry point (root) which segues (push) to a SplitViewController On iPad, when I get into the splitView, I can get back to the root by dragging down the split view. But on iPhone, this does not work: even though presentation is .automatic, Splitview covers all screen. No way to get back. I tried to create a back button in the detail views… Could not get it. What is the best way to do this ? is there a setup for the initial segue or the views presentation modes to allow pop back ? can I add a back button ? Where, calling what action to return ? I cannot embed splitViewController in nav stack … I would like to have the same solution on both iPhone and iPad…
1
0
644
Jun ’21
Search in Download / more broken ?
In the new version of download > More, there doesn't seem to be a way to filter search efficiently. I searched for instance for MacOS (to see all releases). I get a very long list (200+) references, with a lot of Xcode, but nothing specific to MacOS. If I search for Xcode 11, I get all Xcode references: I added quotes to try and force an exact search, I just get a Java extension… That was not the case in the previous version of the more page. Or do I miss something ?
2
0
628
Jul ’21
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
937
Jan ’22
Storyboard display issue
I get this weird behaviour of Xcode. Version 13.2.1 or 13.2 RC (may be other). In the storyboard I had a UITableViewController. As it does not give any flexibility to add other views in the VC, I created a new UIViewController, recreated the tableView inside as well as some other objects, added the new views I needed, redid all connections. Then I removed the UITableViewController. Everything works perfectly fine. But sometimes (cannot find any pattern for the cases), when opening the project, the old UITableViewController appears in Storyboard. The new UIViewController doesn't even seem to be here. When I select different VC in SB, no information in Identity inspector or other inspector. But it compiles and runs OK, using the new UIViewController. I cleaned build folder, closed Xcode, reboot the Mac, to no avail. Only way to get it solved was to close the SB and reopen it… Is there a cache somewhere in SB that is not cleared ?
1
0
1.1k
Mar ’22
Several tags do not open anymore on the forum (today 1/29/2022)
Since a few hours, Sat 1/29/2022, several pages of the forum do not open, such as: https://developer.apple.com/forums/ https://developer.apple.com/forums/tags/ios all showing the same messages: Other tags open without problem. And those open with a payload: https://developer.apple.com/forums/?page=1&sortBy=lastUpdated https://developer.apple.com/forums/search/?q=column&page=1&sortBy=lastUpdated https://developer.apple.com/forums/tags/ios/?page=2 works, but page=1 doesn't Does anyone experience the same errors ? Conf: MacOS 12.2 (21D49) Safari Technology Preview Release 139 (Safari 15.4, WebKit 17613.1.14.41.3) But the pages open correctly on Firefox, Chrome. Does not open either on Safari Version 15.3 (17612.4.9.1.5) So issue is apparently on Safari probably not MacOS 12.2 (21D49) , nor on server side.
5
0
956
Jan ’22
App hangs when setting constraint to a very specific value (a width divided by 2).
I get a surprising crash when adapting constraints. Xcode 13.2.1 iOS 15.2 on simulator Here is the set up in storyboard: A subclass of UIView (PopoverView) to draw a popover like frame and label and button inside. PopoverView can set its arrow position all around, for instance on the right, so that popover will appear on the left of an object, or on the left, to appear on the right. Button tap is used to loop through the arrow position. I have defined constraints (and their IBOutlets), and notably for the centerX position of popoverView to centerX of the label. I adapt the value of the constraints in viewWillLayoutSubviews to position the popover in correct position relative to the label. Now the problem. To position the popover on the right of the label, I set its centerX constraint as follows in viewWillLayoutSubviews(): popoverCenterToLabelCenterConstraint.constant = (popoverLabel.frame.width + label.frame.width) / 2 That works OK To position the popover on the left of the label, I set its constraint as follows (offset the opposite value): popoverCenterToLabelCenterConstraint.constant = -(popoverLabel.frame.width + label.frame.width) / 2 I also tried: popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - label.frame.width / 2 App does not crash but hangs, apparently in an infinite loop. Idem if I divide by 2.0 instead of 2 : label.frame.width / 2.0 The width of the label, at this point of code, is 92.33333333333333 So I replaced by the value directly: popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - 46.2 and it works OK. Idem with 46.1 So the problem is not due to the position of popoverView If I replace the div by 2 by 2.01 : - popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - label.frame.width / 2.01 it works !!!!!! Conclusion: it is the exact div by 2 that causes the hanging. What could be the reason for this strange behaviour ?
3
0
1.2k
Feb ’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
965
Feb ’22
Remote control for iPad from BLE device
I need to implement a remote control for a SwiftUI app running on iPad. I would need to handle 2 different events like Start / Stop. On software side, I plan to use .onReceive to listen to BLE device. So my questions: I need realtime reaction (a few 1/100 s max) can any BLE remote control do the job ? If anyone has tested some low cost remote, I am interested to know. Or should I look for Homekit solutions ? Or use an iPhone as remote controller ?
0
0
889
Dec ’22
List issues with dynamic content
I have encountered the following problem with a List. The setup is as follows @State private var allItems : [SomeItem] @State private var selected   : SomeItem? // in the body List(allItems, $selection) { theItem in … } where SomeItem is a struct. When some properties of an item in allItems changes, the values that I read in theItem are not updated. Just as if old content was cached. I changed allItems to a computed var and everything works OK. I read this SO thread https://stackoverflow.com/questions/74083515/swiftui-list-item-not-updated-if-model-is-wrapped-in-state but that does not give a full explanation. So my questions: Is there effectively an issue here ? when is it safe to use a State var as the Content of List ? Is it OK (it seems) if the properties of items do not change ? It seems also OK if the list of allItems is modified (appended, reduced) without problem changing the properties of its elements. How to do if needed to change both allItems (append for instance) and change the properties of some items, as computed var cannot be modified. Hope the question is clear.
3
0
1.1k
Mar ’23
On daylight saving time change
Last night we change hour for daylight saving time (at 2:00 it would be 3:00). So I made a simple test to set an alarm at 2:10 At 1:59, clock jumped logically to 3:00 no alarm At 3:10, alarm rang (in fact I had turned it off and back on, but that has no influence) I set an alarm at 3:15, of course it rang I set a new alarm at 2:20 It rang at 3:20 Conclusion: Clock app "replicates" the alarms between 2:00 and 2:59 into 3:00 - 3:59. Which is great, not to miss any. Question: Is this specific to Clock app or a more general system behaviour for all time events ? If so, there may be a side effect: I set an event A to turn On a light at 2:45 And set event B to turn it Off at 3:15 Then B will occur before A and the light will remain On There is no perfect solution ("warping" 2:00 - 2:59 into a minute at 3:00 would creates other issues). Extra question: What happens on winter time ? Will alarm ring twice at 2:10 ?
0
0
2.2k
Mar ’23