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 [1] 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…

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…

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…