NSAttributedString colors for Linux

I'm looking for a way to support ANSI colors with NSAttributedString. The primary attributes I need supported are foreground/background color. Ideally I'd like to have this code portable between macOS and Linux. However macOS utilities UIColor for the definition of color. Is there any thought or issue in creating a UIColor-like API for Linux Swift?

My ultimate goal is to be able to be able to generate ANSI, HTML, or RTF.

macOS uses NSColor, not UIColor, and it is part of AppKit, which is not getting an official port for other platforms.

Nothing is stopping you to implement a class with the same name in your framework inside an #if !canImport(Darwin) ... #endif block.

1 Like

Sounds good... I haven't implemented for macOS, but does that mean documentation is wrong (since it only mentions UIColor)?

https://developer.apple.com/documentation/foundation/nsattributedstring/key/1533563-foregroundcolor

Yeah, the documentation doesn't always highlight the differences between platforms.

UIColor only exists on the other Apple platforms (and on those platforms that is the correct class to use with foreground/background color in NSAttributedString)

2 Likes
Terms of Service

Privacy Policy

Cookie Policy