Skip to content

Instantly share code, notes, and snippets.

View ariok's full-sized avatar
🧠
CodeLoving

Yari @bitwaker ariok

🧠
CodeLoving
View GitHub Profile
// Playground - noun: a place where people can play
import Cocoa
/* Node class implementation */
class Node
{
var data:String?
var link:Node?
@ariok
ariok / [Playground]Quicksort_caching.swift
Last active August 29, 2015 14:02
Quicksort in Swift (Not in-place)
import Cocoa
func quicksort(array:Int[])->Int[] {
var less = Int[](), equal = Int[](), greater = Int[]()
if array.count > 1{
let pivot = array[0]
for x in array{
@ariok
ariok / [Playground]Quicksort_caching_generics.swift
Created June 18, 2014 14:49
Quicksort in Swift using Generics (Not in-place)
import Cocoa
func quicksort<T: Comparable>(array:T[])->T[] {
var less = T[](), equal = T[](), greater = T[]()
if array.count > 1{
let pivot = array[0]
for x in array{
@ariok
ariok / [swift]extension_readability.swift
Last active August 29, 2015 14:02
[swift]Extensions to help code readability
import UIKit
class ViewController: UIViewController {
@IBOutlet var searchBar:UISearchBar
@IBOutlet var tableView:UITableView
override func viewDidLoad() {
super.viewDidLoad()
}
@ariok
ariok / [swift]Singleton.swift
Last active August 29, 2015 14:03
[swift]Thread-Safe Singleton implementation
class Manager {
class var sharedManager : Manager {
struct Singleton {
static let instance : Manager = Manager() // let is Thread-safe
}
return Singleton.instance
}
}
@ariok
ariok / [swift]ArrayExtension.swift
Created June 27, 2014 14:56
[swift]Adding support for "indexOf:" and "contains:" to Array
extension Array {
func contains(object:AnyObject) -> Bool {
return self.bridgeToObjectiveC().containsObject(object)
}
func indexOf(object:AnyObject) -> Int {
return self.bridgeToObjectiveC().indexOfObject(object)
}
}
//This code works correctly in the Application target, while in the Test target I get this warning:
//Cast from 'XCUIElement!' to unrelated type 'String' always fails.
//JSON is of type AnyObject?
let fieldErrors = JSON!["errors"] as? [String:String]
//I've already tried to convert this code in a more "swift 2" format using guard and removing the "optional"...nothing changes.
//Request the access to the Calendar
[eventStore requestAccessToEntityType:EKEntityTypeEvent
completion:^(BOOL granted,NSError* error){
//Access not granted-------------
if(!granted){
}
+ (NSDate *)dateWithYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:year];
[components setMonth:month];
[components setDay:day];
return [calendar dateFromComponents:components];
@ariok
ariok / [CoreData]SQLDebug
Created November 29, 2013 16:52
Enabling Core Data SQL Debug mode
// From your project -> Edit scheme
// Tab "Run"
// Section "Argument passed at Lauch"
// Add this argument
-com.apple.CoreData.SQLDebug 1