FAF deciding on filters on post to be syndicated:

Swift: Banking on reduce()

Array ( [post_title] => Swift: Banking on reduce() [post_content] =>
Think of a bank statement with its opening balance, its transactions and its closing balance. Think likewise of a column in an excel spreadsheet where we tally a column, adding together all the amounts using sum(). In Swift, this type of addition is achieved using reduce(), where the opening balance is the initial value, and the output is our closing balance:

let openingBalance = 10.00
let transactions = [-5.54, 10.45, 6.57,-50.00]
let closingBalance = transactions.reduce(openingBalance, combine: {runningTotal, transactionValue in runningTotal + transactionValue})
closingBalance // -28.52
The combine closure is written out in long ... [post_date_gmt] => 2015-06-03 12:59:00 [post_date] => 2015-06-03 08:59:00 [post_modified_gmt] => 2015-06-03 12:59:14 [post_modified] => 2015-06-03 08:59:14 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-1925675302901456679 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-banking-on-reduce.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/1925675302901456679/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-banking-on-reduce.html [syndication_item_hash] => 9ace5a48c838accd0090998bbf330199 ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46079 [1] => 36550 [2] => 43792 [3] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )

Decide filter: Returning post, everything seems orderly :Swift: Banking on reduce()

Array ( [post_title] => Swift: Banking on reduce() [post_content] =>
Think of a bank statement with its opening balance, its transactions and its closing balance. Think likewise of a column in an excel spreadsheet where we tally a column, adding together all the amounts using sum(). In Swift, this type of addition is achieved using reduce(), where the opening balance is the initial value, and the output is our closing balance:

let openingBalance = 10.00
let transactions = [-5.54, 10.45, 6.57,-50.00]
let closingBalance = transactions.reduce(openingBalance, combine: {runningTotal, transactionValue in runningTotal + transactionValue})
closingBalance // -28.52
The combine closure is written out in long ... [post_date_gmt] => 2015-06-03 12:59:00 [post_date] => 2015-06-03 08:59:00 [post_modified_gmt] => 2015-06-03 12:59:14 [post_modified] => 2015-06-03 08:59:14 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-1925675302901456679 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-banking-on-reduce.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/1925675302901456679/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-banking-on-reduce.html [syndication_item_hash] => 9ace5a48c838accd0090998bbf330199 ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46079 [1] => 36550 [2] => 43792 [3] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )

FAF deciding on filters on post to be syndicated:

Swift: Further adventures in flatMap()

Array ( [post_title] => Swift: Further adventures in flatMap() [post_content] =>
After my post yesterday, I looked around the web a bit to see if I could find posts on flatMap() that describe the behaviour in clear terms. I didn't find what I was looking for but I did find plenty on Scala. One or two posts in particular struck me in terms of clarity and helped me to experiment some more in Swift, while others threw me back into the swamp with the monads (and double monads!).

The results of these experiments are presented here.

Strings

If a string is thrown into the map() function what is returned ...
[post_date_gmt] => 2015-06-03 09:40:00 [post_date] => 2015-06-03 05:40:00 [post_modified_gmt] => 2015-06-03 09:44:52 [post_modified] => 2015-06-03 05:44:52 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-4478280195733331227 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-further-adventures-in-flatmap.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/4478280195733331227/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-further-adventures-in-flatmap.html [syndication_item_hash] => ad24dee319f7470e8ea48241fabc972c ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46044 [1] => 46045 [2] => 40084 [3] => 43792 [4] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )

Decide filter: Returning post, everything seems orderly :Swift: Further adventures in flatMap()

Array ( [post_title] => Swift: Further adventures in flatMap() [post_content] =>
After my post yesterday, I looked around the web a bit to see if I could find posts on flatMap() that describe the behaviour in clear terms. I didn't find what I was looking for but I did find plenty on Scala. One or two posts in particular struck me in terms of clarity and helped me to experiment some more in Swift, while others threw me back into the swamp with the monads (and double monads!).

The results of these experiments are presented here.

Strings

If a string is thrown into the map() function what is returned ...
[post_date_gmt] => 2015-06-03 09:40:00 [post_date] => 2015-06-03 05:40:00 [post_modified_gmt] => 2015-06-03 09:44:52 [post_modified] => 2015-06-03 05:44:52 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-4478280195733331227 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-further-adventures-in-flatmap.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/4478280195733331227/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-further-adventures-in-flatmap.html [syndication_item_hash] => ad24dee319f7470e8ea48241fabc972c ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46044 [1] => 46045 [2] => 40084 [3] => 43792 [4] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )

FAF deciding on filters on post to be syndicated:

Swift: What do map() and flatMap() really do?

Array ( [post_title] => Swift: What do map() and flatMap() really do? [post_content] =>

map()

Let's start with map() and feed it an array:
let arr = [1,2,3,4,5,6]
let mapArr = map(arr){$0 * 2}
mapArr // [2, 4, 6, 8, 10, 12]
For those used to closures (and generics), the logic here will be straightforward. We feed map() an array, it works its way through the elements and does stuff to them in order to return a new array. Not only is this true, but the new array that is generated doesn't need to be of the same type as the original array:
let arr = [1,2,3,4,5,6]
let mapArr = map(arr){Double($0) * 2.5}
...
[post_date_gmt] => 2015-06-02 11:43:00 [post_date] => 2015-06-02 07:43:00 [post_modified_gmt] => 2015-06-03 09:57:57 [post_modified] => 2015-06-03 05:57:57 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-5353833862496412229 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-what-do-map-and-flatmap-really-do.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/5353833862496412229/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-what-do-map-and-flatmap-really-do.html [syndication_item_hash] => Array ( [0] => b7c432a314e904566a210b2eaef76ac2 [1] => d1469a4894b6916c4a593088db964d14 [2] => e8bc62866cc412e5fd1b320d04bcb12b ) ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46044 [1] => 46045 [2] => 40084 [3] => 43792 [4] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) [post_name] => swift-what-do-map-and-flatmap-really-do )

Decide filter: Returning post, everything seems orderly :Swift: What do map() and flatMap() really do?

Array ( [post_title] => Swift: What do map() and flatMap() really do? [post_content] =>

map()

Let's start with map() and feed it an array:
let arr = [1,2,3,4,5,6]
let mapArr = map(arr){$0 * 2}
mapArr // [2, 4, 6, 8, 10, 12]
For those used to closures (and generics), the logic here will be straightforward. We feed map() an array, it works its way through the elements and does stuff to them in order to return a new array. Not only is this true, but the new array that is generated doesn't need to be of the same type as the original array:
let arr = [1,2,3,4,5,6]
let mapArr = map(arr){Double($0) * 2.5}
...
[post_date_gmt] => 2015-06-02 11:43:00 [post_date] => 2015-06-02 07:43:00 [post_modified_gmt] => 2015-06-03 09:57:57 [post_modified] => 2015-06-03 05:57:57 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-5353833862496412229 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/06/swift-what-do-map-and-flatmap-really-do.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/5353833862496412229/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/06/swift-what-do-map-and-flatmap-really-do.html [syndication_item_hash] => Array ( [0] => b7c432a314e904566a210b2eaef76ac2 [1] => d1469a4894b6916c4a593088db964d14 [2] => e8bc62866cc412e5fd1b320d04bcb12b ) ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 46044 [1] => 46045 [2] => 40084 [3] => 43792 [4] => 9392 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) [post_name] => swift-what-do-map-and-flatmap-really-do )

FAF deciding on filters on post to be syndicated:

Adventures in PDF: Swift and PDFKit

Array ( [post_title] => Adventures in PDF: Swift and PDFKit [post_content] =>
Working with PDFs in OS X is straightforward using PDFKit.

PDFDocument

It all starts with the PDFDocument class and in order to leverage this you simply import Quartz and get started. Like so:
import Quartz

let url = NSBundle.mainBundle().URLForResource("myPDF", withExtension: "pdf")
let pdf = PDFDocument(URL: url)
pdf.pageCount() // number of pages in document
pdf.string() // entire text of document
As you can see counting the number of pages and accessing the text is straightforward and there's plenty more to explore alongside this, but I want to move quickly along to working with pages.

PDFPage

While you ... [post_date_gmt] => 2015-05-11 11:32:00 [post_date] => 2015-05-11 07:32:00 [post_modified_gmt] => 2015-05-11 11:32:22 [post_modified] => 2015-05-11 07:32:22 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-8044368913261021770 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/05/adventures-in-pdf-swift-and-pdfkit.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/8044368913261021770/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/05/adventures-in-pdf-swift-and-pdfkit.html [syndication_item_hash] => b7f3e19bcdb131eaf366534aa1646b62 ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 6312 [1] => 45395 [2] => 45396 [3] => 45397 [4] => 45398 [5] => 45399 [6] => 45400 [7] => 45401 [8] => 36550 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )

Decide filter: Returning post, everything seems orderly :Adventures in PDF: Swift and PDFKit

Array ( [post_title] => Adventures in PDF: Swift and PDFKit [post_content] =>
Working with PDFs in OS X is straightforward using PDFKit.

PDFDocument

It all starts with the PDFDocument class and in order to leverage this you simply import Quartz and get started. Like so:
import Quartz

let url = NSBundle.mainBundle().URLForResource("myPDF", withExtension: "pdf")
let pdf = PDFDocument(URL: url)
pdf.pageCount() // number of pages in document
pdf.string() // entire text of document
As you can see counting the number of pages and accessing the text is straightforward and there's plenty more to explore alongside this, but I want to move quickly along to working with pages.

PDFPage

While you ... [post_date_gmt] => 2015-05-11 11:32:00 [post_date] => 2015-05-11 07:32:00 [post_modified_gmt] => 2015-05-11 11:32:22 [post_modified] => 2015-05-11 07:32:22 [post_status] => publish [comment_status] => closed [ping_status] => closed [guid] => tag:blogger.com,1999:blog-8073026649714319600.post-8044368913261021770 [meta] => Array ( [enclosure] => Array ( [0] => ) [syndication_source] => sketchyTech [syndication_source_uri] => http://sketchytech.blogspot.com/ [syndication_source_id] => tag:blogger.com,1999:blog-8073026649714319600 [rss:comments] => http://sketchytech.blogspot.com/2015/05/adventures-in-pdf-swift-and-pdfkit.html#comment-form [wfw:commentRSS] => http://sketchytech.blogspot.com/feeds/8044368913261021770/comments/default [syndication_feed] => http://sketchytech.blogspot.com/feeds/posts/default [syndication_feed_id] => 505 [syndication_permalink] => http://sketchytech.blogspot.com/2015/05/adventures-in-pdf-swift-and-pdfkit.html [syndication_item_hash] => b7f3e19bcdb131eaf366534aa1646b62 ) [post_type] => post [post_author] => 561 [tax_input] => Array ( [post_tag] => Array ( [0] => 6312 [1] => 45395 [2] => 45396 [3] => 45397 [4] => 45398 [5] => 45399 [6] => 45400 [7] => 45401 [8] => 36550 ) [category] => Array ( [0] => 5000 [1] => 6003 ) [post_format] => Array ( ) ) )