Twitter | Search | |
Peter Steinberger
Swift experts: Is there a way I can make this less messy? This used to be the same code in ObjC, with some light macro usage. I ported the test to Swift but now it’s this ugly if/else.
Reply Retweet Like More
Peter Steinberger Dec 13
Replying to @steipete
This seems better. Not happy but really Apple to blame for an unfortunate different mapping. Thanks folks!
Reply Retweet Like
Jp LaFond Dec 13
Replying to @steipete
Create an enum/struct that wraps FontDescriptors (as well as UIColor/NSColor) and conforms to the same functions? We did something similar in an old job.
Reply Retweet Like
Peter Steinberger Dec 13
Replying to @JpLaFond
That’s what I ended up with. Seems less elegant than ObjC.
Reply Retweet Like
Eric Amorde Dec 13
Replying to @steipete
I think you can use “[]” for the second line instead of using the raw value initializer
Reply Retweet Like
Peter Steinberger Dec 13
Replying to @_amorde
Good one, thanks!!
Reply Retweet Like
Nick Lockwood Dec 13
Replying to @steipete
Why not just something like os(OSX) fileprivate extension NSFontDescriptor.SymbolicTraits { static let bold = traitBold static let italic = traitItalic }
Reply Retweet Like
Peter Steinberger Dec 13
Replying to @nicklockwood
Hmmmmmm that looks useful, did not think of an extension. Thanks! 💙
Reply Retweet Like
RA Amin Negm-Awad Dec 13
Replying to @steipete
The only known way to make Swift code less messy and ugly is to use Objective-C.
Reply Retweet Like
Peter Steinberger Dec 13
Replying to @RA_Negm
Ha! I see Swift as new challenge! :)
Reply Retweet Like
🌍YH Dec 13
Replying to @steipete
A different typealias depending on the platform ? 🤔
Reply Retweet Like
Peter Steinberger Dec 13
Replying to @yageek
That would make things awkward to use for SDK consumers though; I can’t really wrap that without breaking API, and the header is in ObjC. (Unless I’m missing something)
Reply Retweet Like