Skip to content

Instantly share code, notes, and snippets.

View danielt1263's full-sized avatar

Daniel Tartaglia danielt1263

View GitHub Profile
@maxchuquimia
maxchuquimia / NSAttributedStringConcatenation.swift
Last active May 24, 2019 14:38
Concatenate NSAttributedString in Swift without your code wrapping over multiple lines. Also adding images to attributed strings is supported!
func +(lhs: NSAttributedString, rhs: NSAttributedString) -> NSAttributedString {
let a = lhs.mutableCopy() as! NSMutableAttributedString
let b = rhs.mutableCopy() as! NSMutableAttributedString
a.appendAttributedString(b)
return a.copy() as! NSAttributedString
}
@mzaks
mzaks / debounce.swift
Last active March 4, 2019 09:47
Swift debounce function based GCD
import Foundation
/**
Creates and returns a new debounced version of the passed block which will postpone its execution until after wait seconds have elapsed since the last time it was invoked.
It is like a bouncer at a discotheque. He will act only after you shut up for some time.
This technique is important if you have action wich should fire on update, however the updates are to frequent.
Inspired by debounce function from underscore.js ( http://underscorejs.org/#debounce )
*/
public func dispatch_debounce_block(wait : NSTimeInterval, queue : dispatch_queue_t = dispatch_get_main_queue(), block : dispatch_block_t) -> dispatch_block_t {
@Revolucent
Revolucent / BitwiseOptions.swift
Last active September 22, 2018 12:46
BitwiseOptions implementation for Swift
//
// BitwiseOptions.swift
//
// Created by Gregory Higley on 11/24/14.
// Copyright (c) 2014 Prosumma LLC. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@interface KeyBoardSizeView : UIView
@property (nonatomic,weak) NSLayoutConstraint* heightConstraint;
@end
@kristopherjohnson
kristopherjohnson / NSData_hexadecimalString.swift
Last active July 14, 2018 12:44
Convert NSData bytes to hexadecimal string
import Foundation
extension NSData {
/// Return hexadecimal string representation of NSData bytes
@objc(kdj_hexadecimalString)
public var hexadecimalString: NSString {
var bytes = [UInt8](count: length, repeatedValue: 0)
getBytes(&bytes, length: length)