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
[{ | |
"Argentina": [{ | |
"province": "Buenos Aires (Ciudad)", | |
"code": "CIUDAD AUTÓNOMA DE BUENOS AIRES" | |
}, { | |
"province": "Buenos Aires (Provincia)", | |
"code": "BUENOS AIRES" | |
}, { | |
"province": "Catamarca", | |
"code": "CATAMARCA" |
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
[{ | |
"ALBANIA": { | |
"code": "AL" | |
} | |
}, | |
{ | |
"ALGERIA": { | |
"code": "DZ" | |
} | |
}, |
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
extension Date { | |
init?(iso:String) { | |
let d = ISO8601DateFormatter() | |
guard let date = d.date(from: iso) else { | |
return nil | |
} | |
self = date | |
} | |
func year() -> 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
import UIKit | |
import PlaygroundSupport | |
class ViewController: UIViewController { | |
var redView:UIView! | |
var movedRight:Bool = false | |
var verticalConstraint:NSLayoutConstraint! | |
var horizontalConstraint:NSLayoutConstraint! | |
var widthConstraint:NSLayoutConstraint! | |
var heightConstraint:NSLayoutConstraint! |
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 Cocoa | |
import Security | |
// Adaptation of https://stackoverflow.com/a/37539998/1694526 | |
// Arguments for the keychain queries | |
let kSecClassValue = NSString(format: kSecClass) | |
let kSecAttrAccountValue = NSString(format: kSecAttrAccount) | |
let kSecValueDataValue = NSString(format: kSecValueData) | |
let kSecClassGenericPasswordValue = NSString(format: kSecClassGenericPassword) | |
let kSecAttrServiceValue = NSString(format: kSecAttrService) |
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
extension FileManager { | |
func replaceWithCopyOfFile(at:URL, with:URL) { | |
do { | |
let url = try self.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: with.deletingPathExtension(), create: true) | |
try self.copyItem(at: with, to: url.appendingPathComponent(with.lastPathComponent)) | |
let alert = NSAlert() | |
alert.messageText = "Replace \"\(at.lastPathComponent)\" in \"\(at.pathComponents[at.pathComponents.count - 2])\" with new file?" | |
alert.addButton(withTitle: "OK") | |
alert.addButton(withTitle: "Cancel") |
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 Cocoa | |
import Quartz | |
enum SearchType: Int { | |
case CaseInsensitiveSearch = 1, LiteralSearch, BackwardsSearch, AnchoredSearch, NumericSearch | |
} | |
extension PDFDocument { | |
func pages(withString str:String, searchType type:SearchType) -> [String] { | |
let selec = self.findString(str, withOptions: type.rawValue) |
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
// Follow the horizon | |
import UIKit | |
import PlaygroundSupport | |
import SpriteKit | |
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 300.0)) | |
let view = SKView(frame: CGRect(x:0, y:0, width:375, height:120)) | |
PlaygroundPage.current.liveView = view |
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 | |
// see here for details about date formatter https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369 | |
func time()->(h:Int,m:Int,s:Int) { | |
let formatStrings = ["hh","mm","ss"] | |
var hms = [Int]() | |
let dateFormatter = DateFormatter() | |
let date = Date() | |
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 2 stable sort taken from AirspeedVelocity blog and updated to Swift 3 | |
// http://airspeedvelocity.net/2016/01/10/writing-a-generic-stable-sort/ | |
extension RangeReplaceableCollection | |
where | |
Index: Strideable, | |
SubSequence.Iterator.Element == Iterator.Element, | |
IndexDistance == Index.Stride { | |
NewerOlder