Archive for March 17, 2015

Tuesday, March 17, 2015

Replacing Photoshop With NSString

Charles Parnot:

This “drawing” described very nicely what I wanted to do, better than any comment I could ever write for any kind of code, in fact. That ASCII art was a great way to show directly in my code what image would be used in that part of the UI, without having to dig into the resources folder. The actual drawing code suddenly seemed superfluous. What if I could just pass the ASCII art into NSImage directly?


Xcode does not compile ASCII art, so I decided I would write the necessary ‘ASCII art compiler’ myself. OK, I did not write a compiler, but a small fun project called ‘ASCIImage’! It works on iOS and Mac as a simple UIImage / NSImage category with a couple of factory methods. It is open-source and released under the MIT license on GitHub.

So cool, and it looks like a good excuse to play with Monodraw. It also takes care of the fiddly drawing stuff:

Without anti-aliasing, it is tricky to get the correct pixels to turn black. For this, I found that one should use a thicker line width for 45-degree lines, equal to the diagonal of a 1-pt square: the square root of 2. This width works fine for other angles, including horizontal and vertical lines, thus drawing of the lines is done using this width for aliased rendering, instead of the 1-pt width for anti-aliased rendering.

Update (2015-03-25): Charles Parnot:

The response has been overwhelmingly positive, with lots of excitement, oohs, wows and aaahs. That’s an incredibly fun experience for me.

Here are a few related items to follow-up on all this[…]

There are comments on Hacker News and Reddit.

Using Core Data With Swift

Tom Harrington:

Both Core Data and Swift include the concept of an optional value. But when Xcode generates subclasses, it doesn’t consider whether Core Data thinks the value is optional when generating the Swift file. It generates non-optional properties every time. This conflict means that you end up a Swift non-optional property that could reasonably have a nil value. The compiler sees that the property is not optional, so it doesn’t mind that you aren’t checking this (in fact, Swift rules mean it’s not possible to check, because the property is not optional). This is exactly the kind of problem Swift’s compiler is supposed to catch for you, but here it can’t.

This can lead to crashes.

If you’re using mogenerator, you’re covered for Core Data optionals. It makes sure Core Data optionals become Swift optionals. I’d take it a step farther and make all properties optional in Swift even if they’re required by Core Data. Core Data doesn’t enforce the “required” rule until you save changes, so even non-optional attributes can legally be nil at almost any time.


Although the documentation could be read as meaning that @NSManaged is required, it actually isn’t. It’s only needed if you’ll be letting Core Data handle the accessors. If you’re providing your own, drop it. Core Data’s accessor magic is not documented but it seems you can’t just override it like you’d override other methods.

Force Touch Trackpad

Thomas Brand:

This weekend I had the opportunity to try out the new Force Touch trackpad on the new 13-inch MacBook Pro with Retina display. The sensation of a physical click is so good I had to turn the computer off, disabling the haptic engine, just to make sure I was using the new trackpad. With the MacBook Pro turned off the trackpad doesn’t move. (Clicking on it gives you the same sensation as pressing on the palmrest.) But after turning the MacBook back on, clicking the trackpad gives you the same sensation as the old trackpad where the surface is depressed. Dr. Drang calls this sensation tactile illusion, and it is caused by electromagnets in the haptic engine rapidly shaking the trackpad in a lateral motion. I call it another reason to buy a Mac.

Apple didn’t design the new Force Touch Trackpad just so that it could fit into a thinner Mac. Using the built-in software you can adjust the force of the new trackpad’s click without turning a screw.


Here are some examples what you can do with a Force click.

Dr. Drang:

The trackpad uses four force gauges, one at each corner, to measure the force you exert when pressing down on it. It’s remarkably similar to the way my bathroom scale works. The force gauges are themselves very simple: short cantilever beams with strain gauges on one side. The strain gauges change resistance according to the curvature of the beams, the curvature of the beams changes according to the forces acting on them, and the four forces on the beams add up to the total force of your touch. By putting a gauge at each corner, the force is measured accurately regardless of where you touch.


More interesting to me is the feedback the trackpad gives you. A set of electromagnets along one edge of the pad shake it laterally according to criteria that are a complete mystery to me. Somehow, though, buzzing the pad laterally gives the user the impression of downward motion. Everyone who’s tried it out says the feeling is uncannily like pushing down on a regular trackpad.

Update (2015-03-20): Apple:

Apps can have any button, control, or region on the screen respond to a press of stronger pressure. A Force click can provide a shortcut to additional functionality within the app.


Pressure sensitivity in the trackpad enables apps to give users greater control. For instance, fast-forward in media playback can speed up as pressure increases.


Let users react to a Force click gesture while in the middle of performing a drag, for instance, to immediately open a new target for the drop.


Download the latest release of Xcode 6, which includes OS X 10.10.3 SDK, and use the development resources below to learn more about creating apps that support the Force Touch trackpad.

Here is a summary of what’s new:

Buttons and segmented controls can also now be set as spring loaded. When enabled, the receiver may be activated by dragging something over it and force clicking—pressing harder. When spring loading is enabled and a user drags something over the receiver, the receiver highlights to indicate that it responds to force clicking. In this situation, if the user presses harder, additional highlighting occurs to indicate that the receiver was activated.

Update (2015-03-22): Julio Ojeda-Zapata:

Execution is everything, and the Force Touch trackpad has been implemented impeccably based on what I’ve seen so far. It just works, and is a welcome addition to the MacBook line. I hope Apple makes it possible for desktop Mac users to join the Force Touch party too, with an updated Magic Trackpad.

Excellent though it is, I’m still a mouse guy.

Update (2015-03-30): Thomas Aquino:

The part that struck me about using Force Touch was how useful it was in alerting me that I clicked something. Clicking a word did two things: (1) it showed me the definition; but (2) more importantly, I felt the click at the same time. Feeling my action was key because it let me know that I’m clicking without me having to rely solely on my vision to know that I clicked. And that’s the accessible part – the Force Touch trackpad gives me yet another cue (beyond the popover animation and sound of the click) that something happened.