Latest weblog entries

2016-09-22 Swift 3 naming

Swift 3 is different from version 2 in the naming department. The short version is that the first label of a function is now mandatory, and that the function signature should reflect this.


    func pageViewsfromContent(content: ENFormContent) -> [VIFormPageView]


    func pageViews(fromContent content: ENFormContent) -> [VIFormPageView]

See also:

2016-09-13 weird error when creating constraint in Swift 3

Today, I've transitioned a project to Swift 3 and I bumped into a crash. The crash was as follows:

    -[_SwiftValue nsli_superitem]: unrecognized selector sent to instance 0x170249a50
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue nsli_superitem]: unrecognized selector sent to instance 0x170249a50'
    *** First throw call stack:
    (0x1816741c0 0x1800ac55c 0x18167b278 0x181678278 0x18157259c 0x1820ab104 0x1820a9948 0x1820a879c 0x1820a8340 0x100176cc0 0x10012071c 0x100123474 0x1874b55c8 0x1874cd15c 0x1876556ac 0x18756dd74 0x18756d9dc 0x18756d940 0x1874b2738 0x18497b40c 0x1849700e8 0x18496ffa8 0x1848ecc64 0x1849140d0 0x1874a7e08 0x1816217dc 0x18161f40c 0x18161f89c 0x18154e048 0x182fd1198 0x187520818 0x18751b550 0x10002387c 0x1805305b8)
    libc++abi.dylib: terminating with uncaught exception of type NSException

Turns out this happens at the end of the following bit of code:

 scrollView = UIScrollView()
    scrollView.translatesAutoresizingMaskIntoConstraints = false
    contentView = UIView()
    contentView.translatesAutoresizingMaskIntoConstraints = false
    let viewDict = [
        "contentView": contentView,
        "scrollView": scrollView,
    let vFormat = "V:|[contentView]|"
    let constraints = NSLayoutConstraint.constraints(withVisualFormat: vFormat, options: [], metrics: nil, views: viewDict)

Yeah, I've been creating UIView objects by hand instead of using Interface Builder. Like a savage! After playing with the debugger, it turns out the compiler infers the type of the viewDict as a [String: UIView?] and do notice that UIView optional.

The problem is fixed by declaring the viewDict as follows:

  let viewDict: [String: UIView] = .....

Just leaving this here for DuckDuckGo, plus I've answered a similar question on StackOverflow.

2016-08-16 Filter array in Swift

Here's a bit of code that you can throw in a playground. Given an array with a bunch of objects, it'll filter the array based on a property. Then it'll print the result.

    class MyObj: CustomStringConvertible {
        var enabled = true
        var text = ""
        init(enabled: Bool, text: String) {
            self.enabled = enabled
            self.text = text
        var description: String {
            return "MyObj=\(text)"
    let collection = [
        MyObj(enabled: true,  text: "ja"),
        MyObj(enabled: true,  text: "jawohl"),
        MyObj(enabled: false, text: "no"),
        MyObj(enabled: false, text: "nope"),
        MyObj(enabled: false, text: "non"),
        MyObj(enabled: true,  text: "yep"),
        collection.filter { $0.enabled }
                  .map { $0.text }

2016-08-11 UIImage nsli superitem

Got this weird error today while futzing around with AutoLayout, or more specifically VFL, Visual Format Language:

    2016-08-11 11:05:00.915 TestTruckButton[74067:6491323] -[UIImage nsli_superitem]: unrecognized selector sent to instance 0x7fb8fbc4ae80
    2016-08-11 11:05:00.924 TestTruckButton[74067:6491323] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage nsli_superitem]: unrecognized selector sent to instance 0x7fb8fbc4ae80'
    *** First throw call stack:
    0   CoreFoundation                      0x000000010301cd85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000104dc3deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000103025d3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000102f6bcfa ___forwarding___ + 970
    4   CoreFoundation                      0x0000000102f6b8a8 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x00000001034037af -[NSLayoutConstraintParser findContainerView] + 49
    6   Foundation                          0x00000001034033ae -[NSLayoutConstraintParser finishConstraint] + 691
    7   Foundation                          0x0000000103402986 -[NSLayoutConstraintParser parse] + 375
    8   Foundation                          0x00000001034025c6 +[NSLayoutConstraintParser constraintsWithVisualFormat:options:metrics:views:] + 91
    libc++abi.dylib: terminating with uncaught exception of type NSException

This happened because you tried to use an UIImage instead of an UIImageView in VFL. Just leaving this here so AltaVista & Co. can find it.

2016-06-12 Veertu the hidden gem

For my last project, I've been using Veertu. I consider it the hidden gem of desktop virtualization. The big boys in this space are basically Parallels, VMWare and VirtualBox. They all require loads of kernel drivers, and personally I like my Mac as bog-standard as possible.

But since last year, there is Veertu. It uses Apple's own Hypervisor framework and it's distributed through the Mac App Store. I consider this a major accomplishment. Recently some Mac apps have been leaving the store citing limitations of one or the other, but these guys have managed to get their virtualization app running in the sandbox that the App Store requires!

Amazing, really. And it's a good product as well. I've been using it to test Ansible scripts. The backend of my client's project was deployed via Ansible but the script hadn't been maintained for some time. It was very nice to kick up a fresh Ubuntu server instance, test the Ansible script and log any issues that occurred so our backend guy could have a look.

And this is a small thing, but shows attention to detail: the IP address is shown in the list of running VMs: veertu5 shows IP-fs8 2016-06-12.png

Veertu is first and foremost an OS X app so looks and behaves very much like you'd expect, unlike for instance VirtualBox. I've read about some limitations related to graphics performance and USB support. For my purposes, I haven't run into these. I did notice it doesn't yet support sparse files, in the sense that when you reserve 20 GB for your VM, it really does reserve 20 gigs on disk. In my case that wasn't a problem; my VMs don't have a long life.

They're updating it all the time; last update was roughly three weeks ago. So for instance the sparse files thing seems to have been fixed.

In any case, since Veertu is free for basic Linux usage, why not try and see if it supports your use case? To give it a shot with the least amount of hassle, install and start Veertu, add a VM and pick Ubuntu Gnome 16.04 desktop. After downloading, the VM will be started. Then instead of installing, select "Try Ubuntu":

veertu ubuntu 2016-06-12.png

Some links:


Weblog Archive

Weblog entries 2016

Weblog entries 2015

Weblog entries 2014

Weblog entries 2013

Weblog entries 2012

Weblog entries 2011

Weblog entries 2010

Weblog entries 2009

Weblog entries 2008

Weblog entries 2007

Weblog entries 2006

Weblog entries 2005

Weblog entries 2004

All weblog entries


Articles, chronologically (latest first). This is pretty old stuff.


Not yet finished. Maybe will never be finished. Maybe they'll get deleted. Who knows?


System administration: