Today I learned why my NSTextField
permits pasting of newline characters even though I set usesSingleLineMode
properly. It’s because I made it conform to NSTextViewDelegate
to cache changes. When you edit text inside of an NSTextField
, you actually type inside a field editor of the window. That’s a shared NSTextView
instance. Most of the hard work of an NSTextField
is done by its cell
, which is an NSTextCell
. NSTextCell
s implement at least the delegate method NSTextViewDelegate.textView(_:shouldChangeTextIn:replacementText:)
– and when you set usesSingleLineMode
, this is actually set for the cell, not the view itself. You can use textView(_:shouldChangeTextIn:replacementText:)
to sanitize input text, and I suspect that’s where the usesSingleLineMode
implementation happens. If your NSTextField
subclass implements this method, the NSTextCell
implementation isn’t called. And since that one isn’t public (it was called “implicit protocol conformance” back in the day), you cannot delegate up in Swift because the compiler knows it isn’t there.
Continue reading …
Earlier this month, I wrote about validating temporary models for forms. The validation returned .complete
or .incomplete
, which doesn’t help much when you want to show what did go wrong. So I came up with a richer validation syntax.
Continue reading …
I wanted to handle a file loading error in a consumer of an RxSwift Observable sequence. But if the sequence itself produces an .error
event, it completes. After fiddling around for a while, I decided to simply use the Result
enum and ended up with Observable<Result<Theme, ThemeError>>
.
Continue reading …
Gordon Fontenot published his StringTemplate library the other day. You can use it as a much better number formatter, for example:
- “5125550001” is your user input
- “(XXX) XXX-XXXX” is your template
- “(512) 555-0001” is the result of applying the template
There are options to ignore overflow or crop the remainder when only inserting part of the required digits. I think that’s pretty slick!
Ian Keen posted an article about type-safe temporary models. You would use them like scratch pad contexts in Core Data: in forms, you collect information into these temporary models and then generate your real objects from them.
Continue reading …
WWDC people noticed that Panic Inc. are coming back to the Mac App Store with their beloved file transfer app, Transmit. This puzzled a lot of people because they moved away from the MAS starting with Coda 2.5 in 2014. Sandboxing was just too restrictive. But now, it seems, the new Mac App Store’s Sandboxing rules will be different enough for Transmit to work. See Panic’s tweets on the topic. The details:
Continue reading …
Watched Robert “Uncle Bob” Martin talk about “The Future of Programming” and wholeheartedly recommend it. In the talk, Uncle Bob brings up interesting points about the growth of the programming profession:
- Roughly every five years, the number of programmers double.
- Conversely, half of the programmers at any point in time have less than 5 years of experience.
- The industry lacks an appropriate amount of teachers, so all the new people will make all the same mistakes over and over again.
Programming does not grow up this way. On top of that, programmer mistakes in everyday devices now are causing lethal damage to real people. Self-regulation inside the profession (which, like traditional crafts, I guess could reduce the onslaught of newcomers) and proper teaching are essential to keep growing and making code more reliable a foundation of modern societies.
That’s part of why I write, too. Because I found it was extremely hard to learn creating applications properly, not just hacking together something that barely works. I want everyone else to have a head-start compared to me. While educating myself, I discovered ancient wisdom in books from the 1970s – stuff you can still tell (or should I say: sell) people today, like how to decouple parts of your system. As if we, as a profession, suffer from collective amnesia. Old wine in new skins.
Now that I know some rough estimates about programming’s exponential growth, this makes sense. There just isn’t enough time and care put into teaching these practices properly. It’s hard enough to equip students with sufficient knowledge to become somewhat dangerous in front of a programming environment. The rest then is delegated to on-the-job training, which I imagine is pretty disappointing for all parties involved.