Under the Bridge

Pencil This In

Managed to get your Apple Pencil delivered yet? If you have, here’s a remarkable burst of creative applications from the redoubtable FlexMonkey for you to try out:

PencilScale – Using an Apple Pencil with an iPad Pro as an Electronic Scale

Following all the interest created by my Plum-O-Meter, I couldn’t resist trying a similar experiment with my newly arrived Apple Pencil, so here’s PencilScale, an iPad Pro application that uses the Pencil as an electronic scale … The update() method simply subtract’s the touch’s force from a base weight (which is set as the current touch force when the ‘zero’ button is pressed) and multiplies it by 140 which gives the weight in grams (very roughly) …and amazingly, that is pretty much all there is to it!

PencilController – Using Apple Pencil as a 3D Controller for Image Editing

My PencilController project is a Swift app for iPad Pro that applies two Core Image filters to an image: a hue adjustment and a colour controls which I use to control the saturation … The hue filter’s value is controlled by the azimuth angle and the saturation is controlled by the altitude angle: when the pencil is vertical, the saturation is zero and when it’s horizontal the saturation is eight (although when the pencil is totally horizontal, its tip isn’t actually touching the screen, so the highest saturation the app can set is about six and three quarters).

PencilSynth – An Apple Pencil Controlled Synthesiser

PencilSynth is an AudioKit powered synthesiser (mis)using the Pencil as a joystick controller. It’s based on AudioKit’s TouchRegions demonstration and works like this:

  • The Pencil’s horizontal position on the screen defines the output frequency
  • The Pencil’s vertical position on the screen defines the output modulating multiplier
  • The Pencil’s altitude angle defines the output carrier multiplier
  • The Pencil’s azimuth angle defines the output modulation index

FurrySketch: Hirsute Drawing with an Apple Pencil

I thought it was about time to play with the Pencil for its intended purpose, sketching, and see how I could use its orientation data to affect brush strokes.

FurrySketch is a Pencil powered drawing application that draws a sort of multicoloured hair and, most excitingly, the hair’s direction matches the angle of the Pencil. It was super simple to write and, at least in my opinion, gives really nice results … If you are writing drawing apps, adding Pencil support is not only super easy, it adds real value for your users. The technique I’ve used here to draw hair is only a few lines of code way from spray cans and air brushes and I genuinely believe the iPad Pro will prove to be an amazing device for creatives.

Seen any other creative applications? Let us know!

Continue Reading →

Playground Power

There’s a new article for your attention up at the official Swift blog, Literals in Playgrounds:

New in Xcode 7.1 is the ability to embed file, image, and color literals into your playground’s code. Literals are the actual values of your data represented in their native format, directly within the Xcode editor. For instance, there’s no need to type “myImage.jpg” in the editor – just drag your image from the Finder and the actual image will appear in-line with your code. Instead of showing RGB values to indicate color, the playground will render a color swatch. Literals in playgrounds behave similarly to code you would otherwise hand-author in regular Swift code, but are rendered in a much more useful manner…

If you’ve been underutilizing those playground thingys so far, Playground Secrets and Power Tips is literally a great way to get up to speed,


and it’s literally up to the minute:

So what’s new in this edition? I’ve done a back to front update to incorporate all the new XCPlayground features in Xcode 7.1 beta 3: the new liveView feature that can be used with views and view controllers (and the XCPlaygroundLiveViewable protocol that supports rendering arbitrary model objects), the new ways to continue execution and capture values, etc.

Also, you’ve probably noticed the move to Markdown this year for playground documentation and Swift Documentation, but now there’s full documentation over at the mothership:

Markup Formatting Reference

Use markup formatting commands to create rich comments in playgrounds and to document your Swift symbols for Xcode quick help. Commands include page level formatting for headers and other elements, inline formatting, and images. Playground formatting commands enable page navigation as shown in the following figure … Swift symbol documentation adds descriptions to symbol completion and quick help for symbols …

So if you’re using those legacy HeaderDoc conventions, why there’s all you need to level up!

And to finish up, perhaps a potpourri of playground posts of particular perspicuity:

General tips: NSHipster’s XCPlayground and Erica Sadun’s multitudinous tidbits

Performance Testing in Xcode Playgrounds: “playground that has a similar function to the “measurePerformance” function in XCT.”

Core Graphics Tutorial Part 3: Patterns and Playgrounds: “draw it in a Swift Playground, and then copy the code to a UIImageView subclass.” Or, Overlooked playground cool stuff #3: “build, preview, and save the image to disk. Perfect for creating masks and labels.”

Swift-Diagram-Playgrounds: “two different approaches to creating Diagrams as value types.”

Numerical Algorithms using Playgrounds: “solve problems that don’t have an analytic solution.”

Continue Reading →

To The Nines

Happy iOS 9 Day! Check out all the good stuff announced over at RayWenderlich.com:

This year marks our 5th annual iOS release celebration: the iOS 9 Feast. The iOS 9 Feast consists of 9 courses:

  • Appetizers: Beginning UIStackView & tvOS Tutorials
  • First Course: iOS Apprentice Fourth Edition
  • Second course: iOS Animations by Tutorials Second Edition
  • Third course: Core Data by Tutorials Second Edition
  • Fourth course: iOS 9 by Tutorials
  • Fifth course: watchOS 2 by Tutorials
  • Sixth course: Swift Apprentice
  • Seventh course: 2D iOS & tvOS Games by Tutorials
  • Eighth course: iOS 9 Tutorial Month
  • Dessert: iOS 9 Feast Giveaway

During the iOS 9 Feast, we’ll help you get fully up-to-speed with iOS 9, Swift 2, tvOS, and watchOS 2 development, no matter how you prefer to learn. You’ll learn about UIStackView, iOS 9 Search APIs, Swift 2 error handling, GameplayKit, and much more.

Plus, we have over $18,000 in giveaways for lucky readers – our biggest giveaway yet!

Other tutorial sites worth a look are Hacking With Swift’s iOS 9 collection and the iOS 9 Day-by-Day series:

And here’s various subtleties worth knowing about:

Shipping an App With App Transport Security

There’s already been lots of great discussion about how ATS works – see, for example, Neglected Potential’s Working with Apple’s App Transport Security. Apple has also provided a descriptive tech note on the feature, clearly documenting the expectations of ATS and the exceptions that remain available to developers. And the community has noted in several articles that turning ATS off entirely is generally a Bad Idea.

This article is aimed at a different purpose: to look at the different speed bumps that can show up while building an app alongside ATS, and to explain how to get around them…

Also see Michael Tsai’s roundups App Transport Security and Shipping an App With App Transport Security.

How iOS 9’s Safari View Controller could completely change your app’s onboarding experience

With Safari View Controller, we now will have a way to “talk” to our webpage and learn a little bit about who the user is, and what they were doing, so we can do all of the following:

  • If the user already is logged into the website, you can seamlessly sign them in…
  • If they are not logged in, tailor the onboarding experience for that specific user…
  • Or, if you want to get fancy, you can even change the “intro” UI to be based on which kind of marketing the user came in from…

iOS: You’re Doing Settings Wrong

One of the apparently less known features for iOS 8 and above is the ability to deep link the user into Settings, where they can enable their Location, Notifications, Contacts, Camera, Calendar, HealthKit, etc for your app as needed…

…this gets even better in iOS 9! The Settings screen will have a back button to take the user directly back into your app! Seriously, there is absolutely no excuse to NOT use this.

Get Your App Ready for iOS 9

… iOS will now send out a notification, NSProcessInfoPowerStateDidChangeNotification, when the system enters or leaves low power mode. You can also query the current power state at any time by checking [[NSProcessInfo processInfo] isLowPowerModeEnabled].

If you have any points in your app where you might be able to save some power it’s now a good idea to check the power state and respect the user’s request to help save their battery.

Querying URL Schemes With canOpenURL

… If you build and link against the iOS 9 SDK you need to whitelist the schemes your app will query. What is important to understand is that this policy can also impact older Apps that have not yet been rebuilt with the iOS 9 SDK…

And top off your iOS 9 saviness by checking out this list of clever people and their clever tips!

Top Tips for iOS 9 Development: 12 Community Tips to Get Your App Ready for iOS 9


iOS-9-Sampler: “Code examples for the new features of iOS 9.”

Advanced Touch Handling in iOS9: Coalescing and Prediction; ForceSketch: A 3D Touch Drawing App using CIImageAccumulator

Add iOS 9’s Quick Actions shortcut support in 15 minutes right now!; Lessons learned with 3D Touch; Developing With 3D Touch; Your 3D Touch Spirit Guide; Adding 3D Touch Quick Actions; Peek & Pop

Getting Started with Search APIs and SFSafariViewController in iOS 9; iOS 9: Getting Started With SFSafariViewController

A First Look at Contacts Framework in iOS 9

iOS 9 Universal Links & Forgotten Passwords

iOS 9 Multitasking Tutorial

Continue Reading →

Xcode Transformers – Settings In Disguise

We’re great fans of .xcconfig files and other textua Xcode build process manipulations around here, and here’s some handy undocumented feature tips for you:

Xcode Build Setting Transformations

Xcode supports the ability to substitute the value of build settings using the $(BUILD_SETTING_NAME) or ${BUILD_SETTING_NAME} syntax in a number of places including Info.plists, other build setting values, and .xcconfig files. In these substitutions it’s also possible to add operators that transform the value in various ways. You may have seen one of these in the Info.plist included in project templates:


This results in the value of the PRODUCT_NAME build setting being transformed into a representation suitable for use in the reverse DNS format used by CFBundleIdentifier. So if PRODUCT_NAME is “Whatever App” the resulting string is “com.company.Whatever-App”.

These transformations can be quite useful but don’t appear to be documented, so here’s the list of available operators and what they do…

Note that these operators can be chained, so you can do things like $(PRODUCT_NAME:lower:rfc1034identifier) or $(CONFIGURATION:upper:identifier).

Be sure to bookmark that for next time you’ve got some manipulating setup to do!

h/t: Michael Tsai!


Sam Marshall writes lots of Xcode-related goodies, check out particularly

The Unofficial Guide to xcconfig files; Managing Xcode; Using Xcode Targets

Continue Reading →

Threading Safety First

Now this is a truly epic investigation of the evolution of how to write a singleton in Swift:


We knew about this “right” method of writing singletons, but we had no proof to back up our reasoning other than postulation … So I decided to do something about it and wrote up every way of initializing a singleton and inspected them at runtime using breakpoints. After analyzing each stack trace for any similarities I came across something interesting – PROOF!

*mic drop*

There’s been a number of other good posts lately in the area of threading and memory safety; we recommend checking out

Atomics in Objective-C

This post talks about the use of OS low level atomic functions (compare-and-swap, fetch-and-increment) to achieve both wait and lock free, thread-safe concurrent algorithms in your iOS/OSX apps.

It introduces a few classes that abstract away the gory details of some of the atomic functions made available by libkern/OSAtomic.h into conceptually simpler components that use Foundation types…

Strong, Weak, and Unowned – Sorting out ARC and Swift

I wanted to stop being unsure about the implications of typing one of those three words before variable / constant declarations, so I finally pulled up the Apple Documentation on ARC and began trying to digest the semantics. This article is an attempt to share what got sorted out in my brain as it regards ARC and Swift…

“Weak, Strong, Unowned, Oh My!” – a Guide to References in Swift

I often find myself worrying about retain cycles in my code. I feel like this is a common concern amongst others as well. I don’t know about you, but it seems like I am constantly hearing “When am I supposed to use weak? And what the hell is this ‘unowned’ crap?!” The issue we find is that we know to use strong, weak, and unowned specifiers in our swift code to avoid retain cycles, but we don’t quite know which specifier to use. Fortunately, I happen to know what they are AND when to use them!

Demystifying Retain Cycles in ARC

Retain cycles in ARC are kind of like a Japanese B-horror movie. When you start as a Cocoa/Cocoa Touch developer, you don’t even bother about their existence. Then one day one of your apps starts crashing because of memory leaks and suddenly you become aware of them, and start seeing retain cycles like ghosts everywhere. As the years pass, you learn to live with them, detect them and avoid them… but the final scare is still there, looking for its chance to creep in.

Tip: Avoid retain cycles without doing the strong to weak dance by passing block parameters instead of remembering to capture weakly.

And Grand Central Dispatch helper frameworks in Swift seem to be quite a thing lately; here’s some for you to check out:

Async: “Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch.”

Eki: “is a framework to manage easily concurrency in your apps that wraps the powerful API Grand Central Dispatch”

GCDKit: “Grand Central Dispatch simplified with Swift.”

iDispatch: “Easy to use wrapper over GCD for iOS.”

KillerRabbit: “THGDispatch module, includes GCD bits such as Queues, Groups, Timer, Semaphore, etc.”

Continue Reading →

Linux Swift Too!

TL;DR: You can download The Swift Programming Language (Swift 2 Prerelease) now, or read online here — go straight to the diffs if you wish — and oodles of good stuff in the Xcode 7 beta notes too!

So you all happy now, we trust? The open sourcing we’d figured had to be coming, but contributing a Linux port of Swift 2.0? That was a bit more so.

Here is what we can tell you so far:

  • Swift source code will be released under an OSI-approved permissive license.
  • Contributions from the community will be accepted — and encouraged.
  • At launch we intend to contribute ports for OS X, iOS, and Linux.
  • Source code will include the Swift compiler and standard library.
  • We think it would be amazing for Swift to be on all your favorite platforms.

We are excited about the opportunities an open source Swift creates for our industry. Baked-in safety features combined with excellent speed mean it has the chance to dramatically improve software versus using C-based languages. Swift is packed with modern features, it’s fun to write, and we believe it will get used in a lot of places. Together, we have an exciting road ahead…

Swift On The Server being the next destination there, we’d say that Linux-port bit is a pretty darn clear declaration of.

And of course, here we go with MOAR REWRITES:

An advanced error handling model provides clear, expressive syntax for catching and throwing errors. It’s also easy to create your own custom error types so you can describe error cases with clear, meaningful names…

New syntax features let you write more expressive code while improving consistency across the language…

  • Powerful control flow with do, guard, defer, and repeat
  • Keyword naming rules unified for functions and methods
  • Protocol extensions and default implementations
  • Extended pattern matching to work in if clauses and for loops

Release notes for the new OSes are interesting too:

And here’s your list of WWDC Session sample code of assorted niftiness.

More collected links and details by Erica Sadun at What you need to know, and no doubt there’ll be plenty of in depth analysis to collect … swiftly!


New stuff from WWDC 2015

ASCIIwwdc.com: Searchable full-text transcripts of WWDC sessions

NSHipster’s iOS 9

Ray Wenderlich’s WWDC 2015 Initial Impressions; What’s New in Swift 2

Michael Tsai’s WWDC 2015 Links

Top 10 WWDC 2015 Videos

Changes to the Swift Standard Library in 2.0 beta 1; Swift Diffs

Swift v2 – Error Handling First ImpressionsSwift v2.0 Error Handling – Revisit; Swift 2: Test Driving the Error Handling; Swift 2 error handling in practice; Keep your Swift Exceptions clean, easy to update and future proof; Lets try! Swift(version: Swift.2); Thoughts on Swift 2 Errors; Swift Exceptions are Swifty: Part 1; Error Handling in Swift 2.0; Everything You Should Know About Error Handling in Swift 2.0 (but Were Too Afraid to Ask); Swift 2.0 Error Handling; Thoughts on Swift 2 Errors

Notes from WWDC 2015: Failing Gracefully: Swift 2.0 Error Handling; Swift 2 Error Handling, Continued

Swift 2.0: Day One (do-try-catch)Closures that Throw: Rethrows in Swift 2.0; Throw What Don’t Throw; Re…throws?

Swift 2 + Xcode 7: Unit Testing Access Made Easy!!!!; Improvements to Unit Testing in Swift with Xcode 7; Test Logs in Xcode

Xcode 7 + Swift 2 resources

Swift 2 – What’s new; Swift 2: The overview; Other New Swift 2 Features

What’s New in Swift 2: repeat-while, guard, defer, ErrorType, OptionSetType, multi-payload enums, if-case, for-case, #available, try!

Notes from WWDC 2015: The Enumerated Delights of Swift 2.0 Option Sets; Exploring Swift 2.0 OptionSetTypes

Exploring Swift 2 Protocol Extensions; Protocol-Oriented Programming is Object-Oriented Programming; The ♥ of Swift; The Ghost of Swift Bugs Future; Introducing Protocol-Oriented Programming in Swift 2; Protocol Oriented Programming; Swift protocol extension method dispatch; Swift Protocols; Swift Generic Protocols; Swift’s Protocol Extensions: A Practical Example

The Genius of Swift 2’s defer; guard & defer

Func Parameters in Swift 2.0Parameter Defaults and Optional Function Parameters in Swift 2.0

Friday Q&A 2015-06-19: The Best of What’s New in Swift

Friday Q&A 2015-07-17: When to Use Swift Structs and Classes

C Callbacks in Swift

Swift 2, Beta 2

Protocol extensions and the death of the pipe-forward operator

Swift 2: SIMD

Similarly different: join(), reduce() and flatMap() in Swift 2

Every Swift Value Type Should Be Equatable; Notions of Equality in Swift

Objective-C in 2015: “Swift 2 isn’t the only shiny new toy.”

Dynamic Swift: “performSelector is now available from Swift.”

Changes to the Swift standard library in 2.0 betas 2..<5

Strings in Swift 2: “In Swift 2, the String type no longer conforms to the CollectionType protocol…”

Understanding flatMap; Map and Flatmap; What do map() and flatMap() really do?; Map and FlatMap Demystified; map all the things!; map & flatMap

Linked lists, enums, value types and identity

Mixins and Traits in Swift 2.0

Nil vs throwsNils vs Throws in #swiftlang Part II

Practical Swift: pages generator – build once, use many

Swift + Guard: Syntactical Sugar Pt.2

Swift 2 Pattern Matching: Unwrapping Multiple Optionals; Match Me if you can: Swift Pattern Matching in Detail; Swift 2: Control Flow Pattern Matching Examples; Pattern Matching in Swift and Ranges and Intervals in Swift and More Pattern Matching Examples; Tuples + Pattern Matching

Swift 2 Beta 6; Up the mix with Beta 6; How to Print: the Beta 6 edition

Swift 2.0: Let’s try?; How to “try?” (Yoda alert); Swift + Error Handling Syntactical Sugar Pt.3; Error Handling: From Objective-C to Swift and Back


Initialization in Swift

Swift 2.1

Continue Reading →

React Nativity

Appropriately enough for 2015, there’s a bit of a “Back to the Future” vibe about the latest excitement in the app development world:

React Native: Bringing modern web techniques to mobile

React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about — learn once, write anywhere…

This is very exciting indeed, we are breathlessly assured. Seems to strike some chord though … can’t quite place it …

Introducing React Native

… and there’s always something to learn from other frameworks. But if there’s one thing Appcelerator and we as community should learn is that it looks like we have to do a better job at getting the word out. The word that Appcelerator has been doing this for years!

Yes, that was it. And while we’re delighting in curmudgeonry:

React.native isn’t

While we’re on the subject of terminological disasters, Facebook’s react.native seems to be doing a good job of muddling the waters.

While some parts make use of native infrastructure, a lot do not:

  1. uses views as drawing results, rather than as drawing sources, has a
  2. parallel component hierarchy,
  3. ListView isn’t UITableView (and from what I read, can’t be),
  4. even buttons aren’t UIButton instances,
  5. doesn’t use responder chain, but implements something “similar”, and finally,
  6. oh yes, JavaScript

None of this is necessarily bad, but whatever it is, it sure ain’t “native”.

Perhaps despite all this, there is indeed some reason that React Native will displace SDK Native for development in the same fashion that Titanium has not; but we’d bet against it, personally. However, there is significant contrary opinion; here’s some of the more interesting ones, along with some resource links:

Diary of Building an iOS App with React Native

Retrospective on Developing an Application with React Native for the obligatory Wenderlich tutorial

React Native For Beginners – The Next Big Thing?

ReactNative.com has a good spread of news and resource links

React.parts: “A catalog of React components”

Custom Native iOS Views with React Native

React Native Fundamentals

Now, one assertion in the above that is worthy of consideration is that the more functional model of React has its design advantages. But as it happens, there’s a way to experiment with React design that is actually native:

Introducing ComponentKit: Functional and declarative UI on iOS

Building user interfaces for iOS requires lots of imperative code. As a developer, you create views, configure them, and add them to the hierarchy. You then have to implement callbacks to controllers, which in turn must change the state of your views. Implementing this two-way data flow, even for a simple UI, can be tedious and error prone … To tackle this challenge, we wanted a better abstraction. We drew inspiration from React and its functional reactive programming model for building UI and made a native, Objective-C++ library called ComponentKit which is now used to render News Feed in the Facebook iOS app…

And how did that work out?

ComponentKit gave us performance and reliability gains in News Feed UI Rendering and made the system easier to reason about. It allowed us to:

  • Reduce the size of our rendering code by 70%. Manual and intricate layout code was completely removed as it was no longer needed.
  • Significantly improve scroll performance. ComponentKit eliminated many superfluous container views and significantly flattened our view hierarchy. A flatter hierarchy means less time spent on the main thread to render UI.
  • Improve test coverage. ComponentKit made it easy to build modular UI for which each piece can then be tested in isolation. We now have almost all of News Feed UI under test coverage using snapshot tests.

Making News Feed nearly 50% faster on iOS

OK, now this, this intrigues us.

If you want to dive deeper into the details of how ComponentKit works you can check out this article from Adam Ernst or the second half of this @Scale talk by Ari Grant.

Why yes, yes we will give that some very serious consideration. Much more serious than switching to JavaScript!


Wait, now apps using JavaScriptCore have Apple’s blessing to update themselves without review? Maybe there is A Dynamic, Crazy, Native Mobile Future—Powered by JavaScript after all. We’d noted that possibility way back in 2011, and got a little more interested in 2013, so maybe 2015 is finally the right year for it!

Caravel: “A Swift event bus for UIWebView and JS.”

An iOS Developer on React Native

Continue Reading →

PaintCode By Numbers

Been waiting patiently for that vector drawing in code PaintCode vs. Android report we promised last year? Well, that kinda wandered off into the weeds. Oops. However, PaintCode continues its relentless march towards ever greater heights of awesomeness in freeing you from PNG tyranny:

PaintCode 2.3 adds 15+ new features, including SVG export

  1. SVG code generation
  2. PDF, AI and EPS import
  3. Completely rebuilt image export
  4. Animated sequence export (“Great for Apple Watch animations!”)
  5. Copy & paste support from Sketch, Illustrator, Pages
  6. Live shape thumbnails in the Shapes & Groups browser
  7. New multithreaded renderer
  8. Support for cut, copy & paste of entire canvases
  9. Support for canvas multi-selection
  10. New way to find out where your library items are used
  11. New, easy way to replace one library item with another
  12. Replace Symbol with its content
  13. Improved PSD and SVG import
  14. Canvas Arrangement
  15. Built-in feedback form

So it’a a better time than ever to check that out. And besides their own excellent tutorials and documentation, there’s an ever growing oeuvre of tips and samples:

A First Project With PaintCode & The Story of Look Up’s Arrow

Create a Resolution Independent iOS8 App and Set Your Images Free

Using PaintCode to Dynamically Create Images in the iOS Football Manager Game Title Challenge

Working With PaintCode And Interface Builder In Xcode

Xcode Live Views: Killing them softly with PaintCode

Responsive iOS Buttons with PaintCode

Creating Custom Animated Buttons

Increasing The Tap Area Of UIButtons Made With PaintCode

Creating Beautiful iOS Controls with PaintCode

MMScalableVectorView: “Turns static PaintCode or Qwarkee code into a UIView that honors the contentMode property.”

FKRBlockDrawing “is a collection of two classes and one category to make creating artwork in code a lot easier. It’s great in conjunction with PaintCode, where the graphics in the examples project are from.”

Recreating MKUserLocationView is a great walkthrough of how to do a tricky control that highlights the benefits of PaintCode nicely.

And just in case you’re taking this all seriously, here is what we confidently predict is the most chuckle-worthy UISwitch you have ever seen:

A rapid prototype of UISwitch built with Swift and PaintCode


Recreating Apple Watch Activity Rings in PaintCode

Core Graphics, Part 1: In the Beginning and Part 2: Contextually Speaking and Part 3: Lines

PaintCode Tutorial for Designers: Getting Started and PaintCode Tutorial for Developers: Getting Started

Preview PaintCode images directly in Interface Builder

Continue Reading →

Tip: Check Your Layout Privilege

On the off chance you haven’t bothered to read carefully the 8.3 point release notes, having been busy fixing up your broken Swift code and all, there’s a subtle time bomb lurking therein for next time you get it building again:

When linking against iOS 8.3, any code that relies on layout information (such as the frame) of a UIButton subview when the button is not in the window hierarchy will need to send layoutIfNeeded to the button before retrieving layout information (such as button.titleLabel.frame) to ensure that the layout values are up to date.

For example, if you had something like this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
// code that sets up the button, but doesn’t yet add it to a window
CGRect titleFrame = button.titleLabel.frame;
// code that relies on the correct value for titleFrame

You now need:

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
// code that sets up the button, but doesn’t yet add it to a window
; // This is also safe pre-iOS 8.3
CGRect titleFrame = button.titleLabel.frame;
// code that relies on the correct value for titleFrame

Yikes. Not sure if there’s any currently in development, but we’ve certainly used and/or written ourselves many pieces of code of that form that are now problematic. Probably a sound plan to audit all your button-creating code … just in case.

h/t: @sanjeetsuhag via @mariozullo!


Looks like layout’s got some pretty serious under the hood revisions: for instance this example

If you construct layout constraints manually … pass in nil for the second view, and that contradicts the the attribute being specified, you’ll now get an exception. Previous OS releases appear to have quietly ignored this transgression on your code’s part.

So yep, better give all your layout stuff a good checking under 8.3. It’s the only way to be sure.

Adaptability Changes in iOS 8.3

“IB started respecting the “relative to margin” option for constraints starting in 8.3” may explain your cells looking different.

Continue Reading →

Evolving Swiftly

What, you say reading the title, a followup to “Swiftly Improving” before 1.2 is even final? No, no, because the language is an example of Intelligent Design, not evolution. (At least, we hope, yes?) The now-for-something-completely-different topic of today is the ever so cleverly logoed


Mendel Swift miliframework for implementing evolutionary/genetic algorithms:

The framework provides an Engine protocol, describing the necessary interface for evolutionary/genetic computation using functions. Individual instantiation, population evaluation, selection, genetic operators (like mutation and crossover) and even termination conditions are all described as functions. This allows you to use techniques such as partial application and function composition to a great effect.

Here’s a video showing the sample application that’s build on top of Mendel in action.

Mendel provides a number of canned implementations for some of those functions, see:

Selections for individual selection functions, such as RouletteWheel and StochasticUniversalSampling

Operators for genetic operators, such as Mutation and Crossover

TerminationConditions for termination conditions, such as terminating after a number of iterations (NumberOfIterations) or terminating when a given fitness threshold is reached (FitnessThreshold)…

Even if you’re not fascinated by GA stuff — and who isn’t? — there’s some pretty nifty Swiftiness to take a look at there! And if you are, the background to this project is

Inspired by http://chriscummins.cc/s/genetics/ and the Functional Programming in Swift book. Hat tip to Watchmaker and Nacho Sotos’ swift-genetics.

And if you’re short of initial ideas to run with this; why, what could be more canonical than Genetic algorithm for “Hello World” ?

h/t: @iosgoodies!

Continue Reading →
Page 1 of 120 12345...»