Skip to content

Instantly share code, notes, and snippets.

struct PersonData {
let name: String
let phoneNumber: Int
}
@EfraimB
EfraimB / PromiseKitCancellablePromise.swift
Created November 22, 2018 11:49
PromiseKit (6.4.1) CancellablePromise
//
// Promise + CancelRequest.swift
// PeopleFinders
//
// Created by Efraim Budusan on 12/13/17.
// Copyright © 2017 Tapptitude. All rights reserved.
//
import Foundation
import PromiseKit
public extension UIView {
private struct ExtendedTouchAssociatedKey {
static var outsideOfBounds = "viewExtensionAllowTouchesOutsideOfBounds"
}
/// This propery is set on the parent of the view that first clips the content you want to be touchable
/// outside of the bounds
var allowTouchesOfViewsOutsideBounds:Bool {
get {
public extension UIView {
private struct ExtendedTouchAssociatedKey {
static var outsideOfBounds = "viewExtensionAllowTouchesOutsideOfBounds"
}
var allowTouchesOutsideOfBounds:Bool {
get {
return objc_getAssociatedObject(self, &ExtendedTouchAssociatedKey.outsideOfBounds) as? Bool ?? false
@EfraimB
EfraimB / example.png
Last active January 11, 2018 10:59
FortuneWheelExample
example.png
class PromiseCancelledError: CancellableError {
var isCancelled: Bool {
return true
}
}
public class CancelablePromise<T> {
var promise:Promise<T>
var cancellable:TTCancellable!
override func viewDidLoad() {
super.viewDidLoad()
label.attributedText = label.attributedText?.replacing(placeholder: "<first>", with: "Don't")
.replacing(placeholder: "<last>", with: "anymore.")
}
extension NSAttributedString {
func replacing(placeholder:String, with valueString:String) -> NSAttributedString {
if let range = self.string.range(of:placeholder) {
let nsRange = NSRange(range,in:valueString)
let mutableText = NSMutableAttributedString(attributedString: self)
mutableText.replaceCharacters(in: nsRange, with: valueString)
return mutableText as NSAttributedString
}