Skip to content

Instantly share code, notes, and snippets.

@khanhldt
khanhldt / OrderedDictionary.swift
Last active March 23, 2020 10:53
OrderedDictionary behaves like a Dictionary except that it maintains the insertion order of the keys, so iteration order matches insertion order.
//
// Created by Khanh Le Do on 16/4/16.
// Copyright © 2016 kloc. All rights reserved.
//
import Foundation
/// Attribution to:
/// http://stackoverflow.com/questions/28633703/insertion-order-dictionary-like-javas-linkedhashmap-in-swift
@khanhldt
khanhldt / CollectionType+Shuffle.swift
Created April 16, 2016 09:38
Extension to CollectionType and MutableCollectionType to shuffle all or part of the collection elements.
//
// Created by Khanh Le Do on 6/4/16.
// Copyright © 2016 kloc. All rights reserved.
//
import Foundation
/// Original shuffle methods given on Stackoverflow:
/// http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift
@khanhldt
khanhldt / LayoutConstraintBuilder.swift
Last active April 16, 2016 09:29
Use XibLayoutConstraintHelper to change the constraint of a view from to the Top Guide instead of Top View, especially useful for xib file development.
//
// Created by Khanh Le Do on 16/4/16.
// Copyright © 2016 kloc. All rights reserved.
//
import Foundation
import UIKit
public class LayoutConstraintBuilder {
@khanhldt
khanhldt / StringUtils.swift
Created April 16, 2016 09:18
Utility function to get the needed height for a string to be displayed in a UIKit component
public static func heightNeeded(text:String, font:UIFont, width:CGFloat) -> CGFloat{
let label:UILabel = UILabel(frame: CGRectMake(0, 0, width, CGFloat.max))
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.ByWordWrapping
label.font = font
label.text = text
label.sizeToFit()
return label.frame.height
}
@khanhldt
khanhldt / LogUtils.swift
Last active April 16, 2016 09:19
Utility class to use a global XCGLogger from anywhere in the project.
//
// Created by Khanh Le Do on 12/3/16.
// Copyright © 2016 estasy. All rights reserved.
//
import Foundation
import UIKit
import XCGLogger
public class LogUtils {
@khanhldt
khanhldt / LayoutConstraintBuilder.swift
Last active April 16, 2016 09:24
NSLayoutConstraint builder that allows quick cloning / creation of a constraint.
//
// Created by Khanh Le Do on 16/4/16.
// Copyright © 2016 kloc. All rights reserved.
//
import Foundation
import UIKit
public class LayoutConstraintBuilder {