This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Give Int, CGFloats, and Floats a `doubleValue` property, like `NSNumber`.`doubleValue` | |
Original By Erica Sadun, (Swift Cookbook recipe 5-1), found here: https://gist.github.com/erica/2f6a38c844573c778b0f | |
Subsequent mutilations by Amitai Blickstein | |
*/ | |
//: Numbers that convert to other types | |
public protocol ConvertibleNumberType: DoubleRepresentable, NumberInitAble {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not mine, forgot to whom to give the credit. :( | |
import Foundation | |
/// Allows `collection.safe.whatever`. Mimics usage of AVFoundation's `collection.lazy.whatever` | |
public struct SafeCollection<Base : Collection> { | |
private var _base: Base | |
public init(_ base: Base) { | |
_base = base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITableViewCellExtensions.swift | |
// HealthBucks | |
// | |
// Created by Amitai Blickstein on 11/28/16. | |
// Copyright © 2016 Amitai Blickstein, LLC. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precedencegroup BooleanPrecedence { associativity: left } | |
infix operator ^^ : BooleanPrecedence | |
/** | |
Swift Logical XOR operator | |
``` | |
true ^^ true // false | |
true ^^ false // true | |
false ^^ true // true | |
false ^^ false // false | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// Swift 3.0 | |
// Helper | |
public extension Character { | |
public var stringValue: String { return String(self) } | |
} | |
extension String { | |
// MARK: - CamelCase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swift 3.0 | |
// snake_cased | |
import Foundation | |
extension String { | |
mutating func snake_cased() { | |
self = self.snake_case() | |
} | |
func snake_case() -> String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Instead of, say: | |
if let definitelyAString = perhapsAString as? String { // yadda... } | |
We now have: | |
String(perhapsAString) // returns a String? (an optional) | |
*/ | |
protocol OptionalLiteralType { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSAttributedString+HTML.swift | |
// | |
// Created by Amitai Blickstein on 6/22/16. | |
// Copyright © 2016 Amitai Blickstein, LLC. All rights reserved. | |
// | |
import UIKit | |
//////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String | |
{ | |
var length: Int { | |
get { | |
return countElements(self) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UIImage (FromURL) | |
+(UIImage*)imageWithContentsOfURLString:(NSString*)URLString; | |
@end | |
//************************************* |