Skip to content

Instantly share code, notes, and snippets.

Avatar
💪
Livin' La Vida Low Carb

Nicolás Miari nicolas-miari

💪
Livin' La Vida Low Carb
View GitHub Profile
View SpriteSceneNavigationDelegate.swift
/// Make the ViewController conform to this protocol
///
protocol SceneKitViewController {
var sceneKitView: SceneKitView! { get }
}
/// Make the ViewController conform to this protocol too
///
protocol SpriteSceneNavigationDelegate {
func present(_ scene: BaseSpriteScene)
@nicolas-miari
nicolas-miari / Array+ExportGif.swift
Last active Aug 29, 2019
Extension to Array<UIImage> to export the images as an animated gif.
View Array+ExportGif.swift
import UIKit
import MobileCoreServices // needed for kUTTypeGIF
extension Array where Element == UIImage {
/**
Writes a looping animated gif to the documents folder, using the receiver's elements as the frames.
Based on [this answer](https://stackoverflow.com/a/46095888/433373) from Stack Overflow.
@nicolas-miari
nicolas-miari / UIBezierPath+Superellipsoid
Created Aug 29, 2019
UIBezierPath extension to draw a 'squircle' (superellipsoid) of arbitrary size and "corner radius"
View UIBezierPath+Superellipsoid
import UIKit
extension UIBezierPath {
/**
Draws the super-elliptic analog of a rounded rect. Unlike the regular rounded rect, the rounded corners
are the quadrants of a superellipse (i.e., parabolic segments), _not_ circular arcs.
If `rect` is a square and `cornerRadius` is equal to half the length or more, and actual superellipse is
drawn (no straight sections along its boundary) just like doing the same with a rounded rect results in a
circle being drawn.
@nicolas-miari
nicolas-miari / CGFloat+Tau.swift
Last active Apr 20, 2018
Tau Support for CGFloat
View CGFloat+Tau.swift
import CoreGraphics
extension CGFloat {
/// See this: https://tauday.com/tau-manifesto
static var tau: CGFloat {
return 2 * CGFloat.pi
}
}
@nicolas-miari
nicolas-miari / NSError+Shorthand.swift
Last active May 22, 2017
Swift extension that provides convenient shorthands for initializing `NSError` objects.
View NSError+Shorthand.swift
/**
Provides convenient shorthands for initializing `NSError` objects.
*/
extension NSError {
/**
Same as `init(domain:code:userInfo:)`, but `domain` defaults to the app's
bundle indentifier.
*/
convenience init(code: Int, userInfo: [NSObject : AnyObject]?) {
let bundleIdentifier = NSBundle.mainBundle().bundleIdentifier!
@nicolas-miari
nicolas-miari / UIImage+CalculateOnScreenSize.swift
Last active May 22, 2017
UIImage Calculate On-Screen Size (UIImageView: AspectFit)
View UIImage+CalculateOnScreenSize.swift
extension UIImage {
/**
Calculates the resulting size (rendered on screen) of the receiver when it
is displayed within a `UIImageView` instance of bounds size `containerSize`
that has its `contentMode` property set to `.ScaleAspectFit`.
- parameter contanerSize: The size of the hypothetical UIImageView instance
that is to display the receiver on screen.
- returns: the effective size at which the receiver would be rendered on
screen if displayed in said view.
@nicolas-miari
nicolas-miari / UIColor+CreateFromByteValues.swift
Last active May 22, 2017
Create a UIColor instance with `RGBA` values in the integer range [0, 255] (instead of float [0.0, 1.0])
View UIColor+CreateFromByteValues.swift
import UIKit
extension UIColor {
convenience init(
redByte red: UInt8,
greenByte green: UInt8,
blueByte blue: UInt8,
alphaByte alpha: UInt8
) {
self.init(
@nicolas-miari
nicolas-miari / Image Scale Factor from File Name
Created Dec 18, 2014
Extracts the scale factor (e.g. 1x, 2x, 3x) of an image file name as a float.
View Image Scale Factor from File Name
- (CGFloat) imageScaleFactorFromFilename:(NSString*) imageFileName
{
NSString* filename = [imageFileName stringByDeletingPathExtension];
NSArray* components = [filename componentsSeparatedByString:@"@"];
if ([components count] > 1) {
// Hi res image
NSString* scaleSubstring = [components objectAtIndex:1]; // e.g. @"2x"
View DeviceAndModel.h
@interface MyClass
- (NSString*) deviceName;
@end