Skip to content

Instantly share code, notes, and snippets.


David Rönnqvist d-ronnqvist

View GitHub Profile
d-ronnqvist / gist:22f40a2f52f48ccf7e89
Created May 7, 2015
Drawing a clipped gradient beyond the start and end points
View gist:22f40a2f52f48ccf7e89
import Foundation
import UIKit
class MyView: UIView {
override func drawRect(rect: CGRect) {
// just some path
let path = UIBezierPath(roundedRect: CGRectMake(10, 10, 200, 100), byRoundingCorners: .TopLeft | .BottomRight, cornerRadii: CGSizeMake(30, 60))
// fill with red
d-ronnqvist / Hexagon Ripple.swift
Created Dec 22, 2014
Hexagon Ripple in a Swift Playground
View Hexagon Ripple.swift
import AppKit
import QuartzCore
import XCPlayground
// Parameters that define the style
let hexSideLength: CGFloat = 15.0
let hexLineWidth: CGFloat = 3.0
let colors = [NSColor.redColor(), NSColor.cyanColor(), NSColor.greenColor(), NSColor.yellowColor(), NSColor.redColor()].map { $0.CGColor }
d-ronnqvist / gist:7ea8b1dc7d10f23917c2
Created Dec 10, 2014
I'm designing something where there are multiple different objects that can hold exactly _one_ out of a couple of different other types, and I don't know what style I prefer.
View gist:7ea8b1dc7d10f23917c2
// I'm designing something where there are multiple different objects that can hold
// exactly _one_ out of a couple of different other types, and I don't know what style I prefer.
// For example, an Input always has a name and it can hold a Symbol, a Target, or a Texture.
// It should always hold exactly one of them. In just the same way, a Symbol has a name and can
// hold different data of exactly exactly _one_ type of many.
// Which one of the following alternatives do you prefer?
d-ronnqvist / gist:a70e6a1623bc7da85f1d
Last active Aug 29, 2015
The formatting horrors you sometimes need to go through to fit Objective-C in a two column layout
View gist:a70e6a1623bc7da85f1d
- (NSURL *) writeImage:(NSImage *)image
withSceneDocumentURL:(NSURL *)documentURL
originalImageURL:(NSURL *)originalImageURL
if (!originalImageURL) {
// Let the default exporter write this image
return nil;
NSString *sceneFileName =
[documentURL lastPathComponent];
d-ronnqvist / gist:89768210611e18417b6d
Created Oct 19, 2014
Swift alternative to class clusters?
View gist:89768210611e18417b6d

I wanted to use enums, structs, and classes to create small, elegant objects for a basic chess game.

It started with the small squares in the chess board, and created the logic part in the main definition and an extension that is use for rendering

enum Row: Character {
    case A = "A"
    case B = "B"
    case C = "C"
    case D = "D"
View UIView bounds

The UIView animation API results in different CAAnimations being added to the layer on iOS 7 and 8. Changing the bounds of a view like this:

[UIView animateWithDuration:0.3 
    self.myView.bounds = CGRectMake(0, 0, 100, 100); // was (0,0) (200, 200)

will result in one animation for the bounds key path being added to the backing layer if you are running iOS 7:

d-ronnqvist / synthesize-readonly-in-subclass.m
Created Jul 14, 2014
Synthesizing a read-only property in a subclass overrides custom accessor
View synthesize-readonly-in-subclass.m
@interface Foo : NSObject
// some read-only property ...
@property (nonatomic, copy, readonly) NSString *bar;
@implementation Foo
// ... with a custom accessor
- (NSString *)bar
return @"Foo";
d-ronnqvist / re-enable delete action.markdown
Last active Jul 19, 2018
How to break (and re-enable) the native accessibility "delete" action for table views
View re-enable delete action.markdown

If you've haven't seen it before, there is a cool accessibility feature in UITableView that allows the user to toggle between different actions. It's really very elegant and it's a powerful and convenient implementation for VoiceOver users on iOS. One could say that it's the VoiceOver version of the swipe-to-delete feature.

To try it out yourselves, open one of the built in apps like Mail or Notes and turn on VoiceOver. If you are afraid to accidentally delete some of your important notes or email, you can also create a new Master-Detail Application in Xcode and run it on your device. Navigate to one of the cells and use the "Rotor" (rotate with two fingers on the screen) to find the "Actions" item. Now you can swipe up and down do toggle between "Activate Item (default action)" and "Delete". If you now double tap, the cell gets deleted instead of selected.

image with actions

This is the default behavior and you get this accessibility out of the box with UITableView.


Keybase proof

I hereby claim:

  • I am d-ronnqvist on github.
  • I am ronnqvist ( on keybase.
  • I have a public key whose fingerprint is 710B 9F42 55FC B0E9 DB06 9C2A 563F 6E00 ACB3 4F92

To claim this, I am signing this object:

d-ronnqvist / Thoughts on removedOnCompletion in
Last active May 16, 2020
What I think is wrong with the Spark Recording Circle code and why
View Thoughts on removedOnCompletion in

There was [a tweet][tweetSoto] a couple of days ago that resulted in a discussion/question about what it wrong with the usage of removedOnCompletion = NO in the [SparkRecordingCircle code][code] for that [Subjective-C post][post].

We all kept saying that the explanation doesn't fit in a tweet, so here is my rough explanation about the issues.

But, let me first say that I think that the Subjective-C articles are reallt cool and useful to learn from. This is trying to reason about the general usage of removedOnCompletion = NO, using that code as an example, since that was what was discussed on twitter.

The root problem, as [Nacho Soto pointed out][rootProblem], is that removedOnCompletion = NO in combination with fillMode = kCAFillModeForwards is almost always used when you are not updating the model layer. This means that after the animation has finished, what you see on screen is not reflected in the property of the layer. The biggest issue that this can cause is that all the

You can’t perform that action at this time.