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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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 ?
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 ?
I decode an object with NSKeyedArchiver (SecureCoding):
typealias BoolArray = Array<Array<Bool>>
let val = decoder.decodeObject(of: NSArray.self, forKey: someKey) as? BoolArray
I get the following 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 changed by adding NSNumber.self in the list :
let val = decoder.decodeObject(of: [NSArray.self, NSNumber.self], forKey: someKey) as? BoolArray
No more warning in log.
Is there a reason for this ?
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 ?
I have defined a class :
class Item: NSObject, NSSecureCoding {
var name : String = ""
var color : ColorTag = .black // defined as enum ColorTag: Int
var value : Int = 0
static var supportsSecureCoding: Bool {
return true
}
Its decoder includes the following print statement to start:
required init(coder decoder: NSCoder) {
print(#function, "item should not be nil", decoder.decodeObject(of: Item.self, forKey: someKey))
Another class uses it:
class AllItems: NSObject, NSSecureCoding {
var allItems : [Item]?
static var supportsSecureCoding: Bool {
return true
}
and decodes as follows
required init(coder decoder: NSCoder) {
super.init() // Not sure it is necessary
allItems = decoder.decodeObject(of: NSArray.self, forKey: mykey) as? [Item]
print(#function, allItems) // <<-- get nil
}
I note:
decoder returns nil at line 5
I have tried to change to
decoder.decodeObject(of: [NSArray.self, NSString.self, NSColor.self, NSNumber.self], forKey: mykey))
Still get nil
And, decoder of class Item is not called (no print in the log)
What am I missing ?
I need to encode and decode Array<Array>
SomeStruct is multiplexed in an Int
The former API did work:
if let format = decoder.decodeObject(forKey: someKey) as? Array<Array<SomeStruct>> { }
But using the new API
if let format = decoder.decodeObject(of: Array<Array<Int>>.self, forKey: someKey) {
generates an error:
Cannot convert value of type 'Array<Array<Int>>.Type' to expected argument type '[AnyClass]' (aka 'Array<any AnyObject.Type>')
encoding is done as follows:
var format = Array(repeating: Array(repeating: 0, count: 4), count: 4)
// initialize the var
coder.encode(format, forKey: someKey)
What is the correct syntax ?
I have a large code that I try to update to change deprecated APIs.
In the former version, I used forWritingWith and forReadingWith
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWith: data)
archiver.encode(myObject, forKey: theKey)
if let data = NSMutableData(contentsOf: anURL) {
let unarchiver = NSKeyedUnarchiver(forReadingWith: data as Data)
let myObject = unarchiver.decodeObject(forKey: theKey) as! TheObjectType // <<-- returns the object
That I changed to
let data = NSMutableData()
let archiver = NSKeyedArchiver(requiringSecureCoding: true)
archiver.encode(myObject, forKey: theKey)
if let data = NSMutableData(contentsOf: anURL) {
do {
let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data as Data)
let myObject = unarchiver.decodeObject(forKey: theKey) as? TheObjectType // <<-- This returns nil
This builds correctly.
But on execution, unarchiver.decodeObject now returns nil.
I have searched extensively to find the cause to no avail.
I may probably change the design to avoid NSKeyedArchiver, but that would be a huge refactoring.
I probably miss something obvious.
Could someone hint at the possible cause ?
I got accidentally this graph whilst playing with the periods of display in AppStoreConnect Trends
hourly graph
on several days
But when I try to recall it, no way. If I select a multi days period, hourly graph is not available.
Someone has an idea how to get it again ? Or was I lucky to profit of a forums bug ?
Here are the settings for the graph I cannot select again.
I used to resize images (editing width and height when writing the post) in order to avoid ridiculously large images in reading published post.
Since a few weeks, that does not work anymore.
When I edit, I see the reduced size in Live Preview:
But once posted, images are much larger as seen below:
Looks like the image is now resized to fill full width.
I filed a bug report: Dec 27, 2025 at 1:43 PM – FB21446929
PS: that change ignores @eskimo wise advice "Quinn’s Top Ten DevForums Tips" n°10 (https://developer.apple.com/forums/thread/706527).
According to this news, we don't need anymore (at least temporarily): https://www.macrumors.com/2025/12/23/texas-app-store-law-blocked/
A Texas federal judge today blocked an App Store age verification law that was set to go into effect on January 1, 2026, which means Apple may not have to support the changes after all.
Hope we shall get very rapidly more information from Apple.
I'm struggling to implement required code for SB2420 compliance.
I try to learn on a very simple use case.
the app is UIKit
Build in Xcode 26.2
it displays a single Hello view with a button that will simply show a "Good day" label.
I assume the app will be rated 4+.
I tried the following code, using available information in Xcode (limited):
import UIKit
import DeclaredAgeRange
// other import needed ?
class ViewController: UIViewController {
@IBOutlet weak var welcomeLabel: UILabel! // initially hidden
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func testAgeRange() -> Bool {
if !isEligibleForAgeFeatures { // Not found. Which import needed ?
return true // Not called from Texas
}
// Following code from Xcode doc…
do {
let response = try await AgeRangeService.shared.requestAgeRange(ageGates: 13, 15, 18) // Compiler Error: Missing argument for parameter 'in' in call
// Can I add the 4 gate ?
guard let lowerBound = response.lowerBound else {
// Allow access to under 13 features.
return false
}
var ok = false
if lowerBound >= 18 { // Not needed ?
// Allow access to 18+ features.
ok = true
} else if lowerBound >= 15 { // Not needed ?
// Allow access to 15+ features.
ok = true
} else if lowerBound >= 13 { // Not needed ?
// Require parental consent ?
// Allow access to 13+ features.
ok = true // if consent OK
} else {
// Require parental consent ?
// Show age-appropriate content
ok = true // if consent OK
}
return ok // Authorized for all 4+
} catch AgeRangeService.Error.notAvailable {
// No age range provided.
return false
}
}
func executeStart() {
welcomeLabel.isHidden = false
}
@IBAction func start(_ sender: UIButton) {
if #available(iOS 26.0, *) {
if testAgeRange() {
// Need to test for parental control here ?
} else {
// Alert and exit the app ?
}
} else {
// do nothing ? Can we run the app ?
}
executeStart()
}
}
The logic would be:
before allowing action with the start button, check
is it IOS 26+ so that we can call API
if so, is verification needed (Texas SB2420)
if not, we can proceed
if required, test age range
As app is 4+, all ranges should be OK
But need to test parental control
Now, many pending questions in code:
line 14: get an error: Cannot find 'isEligibleForAgeFeatures' in scope
line 19: I used the documentation sample for AgeRangeService, but get a Compiler Error: Missing argument for parameter 'in' in call
line 35: how to implement parental control ?
In addition, in the metadata of the app, should I declare that parental control ?
Age verification?
Mechanism for confirming that a person's age meets the age requirement for accessing content or services
As there is no restriction on age, is it required ?
Any help welcomed as well as link to a comprehensive tutorial.
Since recently, when I try to close a thread I created on an answer of mine, I get the following error:
Trying later, next day, does not solve it. In the list of all threads, the post is not marked as answered.
But if I look via Chrome or plain Safari, I see the answer itself is marked as correct:
Which is not the case when opening in Safari Technology Preview (Release 233) where the same answer is still to be accepted:
If an app is rated 4+, does it have any additional obligation due to the SB2420 beyond this rating on the AppStore ?
After porting code to Swift 6 (Xcode 16.4), I get a consistent crash (on simulator) when using UNUserNotificationServiceConnection
It seems (searching on the web) that others have met the same issue. Is it a known Swift6 bug ? Or am I misusing UNUserNotification ?
I do not have the crash when compiling on Xcode 26 ß5, which hints at an issue in Xcode 16.4.
Crash log:
Thread 10 Queue : com.apple.usernotifications.UNUserNotificationServiceConnection.call-out (serial)
As far as I can tell, it seems error is when calling
nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
I had to declare non isolated to solve a compiler error.
Main actor-isolated instance method 'userNotificationCenter(_:didReceive:withCompletionHandler:)' cannot be used to satisfy nonisolated requirement from protocol 'UNUserNotificationCenterDelegate'
I was advised to:
Add 'nonisolated' to 'userNotificationCenter(_:didReceive:withCompletionHandler:)' to make this instance method not isolated to the actor
I filed a bug report: Aug 10, 2025 at 2:43 PM – FB19519575
Topic:
App & System Services
SubTopic:
Notifications
Tags:
Swift
Xcode
Notification Center
User Notifications