Hacker News new | past | comments | ask | show | jobs | submit login
Swift gems for creating reliable, concurrent OS X desktop apps (pixelspark.nl)
46 points by misterdata on June 8, 2015 | hide | past | web | favorite | 7 comments



Shameless plug for my tiny implementation of Promise (similar to the Future type mentioned in the article)[1].

I've used it in a few projects, and it makes dealing with async things feel surprisingly natural:

    getLocation()
        .then { apiRequest(params, location: $0) }
        .then { json -> () in
            for result in json["results"] {
                display(result)
            }
        }
        .catch { showError($0) }
It's also easy trivial to adapt existing callback-based[2] and delegate-based[3] APIs to promises.

[1]: https://gist.github.com/Sidnicious/93d2a8db1266e2fd239c

[2]: https://gist.github.com/Sidnicious/69df2c483aadc08bda4f

[3]: https://gist.github.com/Sidnicious/99b099d9b6f2ecb9e383


The Failable type in the article looks like this Result project on GitHub [1]. It makes for interesting related reading.

[1]: https://github.com/antitypical/Result


If this interests you, definitely consider taking https://www.coursera.org/course/reactive


> LOGGING FROM DIFFERENT BACKGROUND THREADS AT ONCE

Or, you could just make a logging serial queue that you send all log messages to; that way there's no risk of activity on the main thread slowing down your logging. In (Obj-)C:

    static queue_t queue;
    void log (NSString *message) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            queue = dispatch_queue_create("logging", DISPATCH_QUEUE_SERIAL);
        });
        dispatch_async(queue, ^{
            NSLog(message);
        });
    }


This only works right if none of the frameworks you use log anything by themselves - messages will get garbled otherwise. Logging through the main queue exhibits the same issue, but at least Cocoa logging (which is always in the main thread) is dealt with.


I seem to be getting an invalid certificate warning on this site, is this happening for anyone else?


The site uses the StartCom CA, which offers free SSL certificates. I like their service, but I remember that my old OS X 10.5 box does not recognise them, either. It seems to be a relatively recent addition:

http://www.istartedsomething.com/20091010/microsoft-free-roo...




Registration is open for Startup School 2019. Classes start July 22nd.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: