Peculiar inheritance of enum

It turns out that Swift 3 nested enums combine options, but it's not inheritance. It's a little know "feature" you should be aware of when designing API with Swift 3. I didn't know that, and my (I have to admit reasonable assumption) lead to the problem that can't be easily…

Conditional Swift testing

The problem Some tests need to be skipped when executing on CI (continuous integration like travis.org). What tests? In my case, it's performance tests. Why? because I can't trust all CI results and sometimes, randomly, some tests will fail without good reason, like this one: error: testPerformance : failed: The…

Package.swift - manual

Here is documentation for SPM manifest file Package.swift. I couldn't find a list of possible configuration values for Package.swift, so I created one, for future reference. I put here all available settings, with examples of use. Please find examples at the end of the post. Preamble Package.swift…

Documenting Swift protocol

In Swift, I can write documentation at a protocol level now. There is a kick-ass feature added recently to Xcode 8 (beta 4). If I add documentation of function at the protocol level, it's available at the level of implementation. look, I wrote documentation to Task.run() and I can…

Status of Portable Swift code

Portable Swift source code is so damn hard to do. Main problem is that OSX and Linux Swift is using different Foundation codebase. Linux is using SwiftFoundation and OSX is using Foundation. What's the difference ? Foundation vs SwiftFoundation Foundation is written in Objective-C, it's complete and stable. SwiftFoundation on the…

Overload Swift type ambiguity

I may define default type for overloaded functions. sometimes. This is Swift return overloading that may lead to ambiguity: extension String { func encode() -> NSData? { return self.dataUsingEncoding(NSUTF8StringEncoding)?.base64EncodedDataWithOptions([]) } func encode() -> String? { return self.dataUsingEncoding(NSUTF8StringEncoding)?.base64EncodedStringWithOptions([]) } } I have two functions encode() that returns value of…

Retry! in the wild

In perfect world every action finish with the success. In real world it's not. In perfect world sending network request returns with a result. In real world it fail sometimes due to dozen of reasons, and since we're living in the real world I have to deal with it. don't…

Linux compatible Swift and Swift Package Manager

Apple opensourced Swift today, as promised in early 2015. This is great, awesome etc... but I'm not about that here. Together with Swift - programming language, Apple presented Linux port of Swift compiler and some tools. One of the tools is Swift Package Manager - that's the reason of this…

Swift reflection about food

Reflection in practice Reflection technique may be useful to build quasi generic functions that operate at runtime. It may be quasi type safe, though it uses runtime too - as such can't be optimised/validated during compilation. With Objective-C we used <runtime/objc.h> and do all the…

Where "where" may be used?

This is by far the most faved/retweeted Swift tip of mine lately: don't forget you can do this 🎉 in Swift #swiftlang pic.twitter.com/izVlfcqOYv— Marcin Krzyzanowski (@krzyzanowskim) November 10, 2015 indeed cool, unexpected and forgettable feature of Swift pattern-matching. The fact is you can use…

Swift London about Natalie, the talk

Earlier this month (October 19, 2015), I had the pleasure to be part of Swift London meetup. I talked about Natalie - Storyboard Code Generator presenting my approach to the "problem" of Storyboards and Swift. Below you can find my presentation, along with an amateur video recording (captured by iPhone)…

ChunkSequence 🔪🍰

Have cake and eat it Have a cake and consume the cake by the Swift function, at the same time. Magic. The nature of the Swift type is that it is copied or copied on write. When I assign A to B (A = B), then effectively B is copy of…

Generic Array of Int - what, why, how?

One of the great feature introduced by Swift 2.0 is possibility to define generic functions for type of Array. Array is container for values of some type. The type is known upfront. It's called Element now. what? Array is a struct with element and is defined like this: struct…

Fast pattern search in Swift... since 1974

the fastest known ways to find one string of characters in another Stay with me. At the beginning brief introduction, later on Swift implementation, tests and conclusion. Halt and Catch Fire thing I really enjoy Halt and Catch Fire tv show. Season 1 was about hardware, while season 2 is…

Collection Index and magic factor

An index is an indirect shortcut derived from and pointing into, a greater volume of values, data, information or knowledge. (wikipedia) In general (however it is not the rule) in modern programming languages Index values start at 0 position and ends at "length - 1" position. A lot of fathers…

Practical Swift: pages generator - build once, use many

In the real world, at some point, we all have to deal with data that is fetched from a backend service, page by page. It's called paging. Everybody does this! Nothing to be ashamed of ;-) Here is one of the ways in which a Swift pattern (well, not specific…

Swift optimizer considered harmful

For some time I struggled with one weird bug reported to CryptoSwift. Few people report that sometimes they got mangled result of decryption with AES. Turn out the code that produce mangled output was PKCS7 class, with part responsible for removing padded bytes. this very function: public func remove(bytes:…

CryptoSwift, the talk

Earlier this year I gave talk named "CryptoSwift: Cryptography You Can Do". The video was recorded on Swift Summit Conference in London, earlier this year. Thanks to realm.io and Swift Summit team, transcript, video and presentation is available online. I encourage you to check it here: https://realm.io/…

Let's talk about sections for NSTableView

Today, let's talk about table view in AppKit for OS X. Programming for OS X have a long history behind. History that is not always known to the iOS programmers, however it is the Mother of UIKit. An NSTableView object displays data for a set of related records, with rows…

Natalie - Storyboard Code Generator

A strongly-typed language like Swift is a big blessing. I truly love how refactoring of code becomes a less scary operation. Today if I change the type of a variable, it won't compile (ok, I can hear you ask about "Any"... just don't), and when it won't compile, it won't…