Skip to content

Instantly share code, notes, and snippets.

@matnogaj
matnogaj / SingleTapTextView.swift
Last active August 17, 2016 11:16
Text view that directs to links immediately without any delay.
class SingleTapTextView: UITextView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
setup()
}
@matnogaj
matnogaj / Detect.swift
Created August 11, 2016 11:07
Detect type of view that is touched in the whole app
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
// ...
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// ...
let tap = UITapGestureRecognizer(target: self, action: #selector(AppDelegate.tap(_:)))
window?.addGestureRecognizer(tap)
tap.delegate = self
tap.cancelsTouchesInView = false
// ...
enum Router: URLRequestConvertible {
static let baseURL = NSURL(string: "https://littlebitesofcocoa.com")!
case Bites
case Bite(Int)
case BitesTagged(Int)
var URL: NSURL { return Router.baseURL.URLByAppendingPathComponent(route.path) }
var route: (path: String, parameters: [String : AnyObject]?) {
@matnogaj
matnogaj / UITextField+Empty.swift
Created May 20, 2016 19:46
Text field check for being empty.
extension UITextField {
var isEmpty: Bool {
guard let text = text else { return true }
return text.isEmpty
}
}
@matnogaj
matnogaj / UIViewController+Present.swift
Created April 26, 2016 05:12
Display custom animated modal view
import UIKit
extension UIViewController {
func presentFromRight(controller: UIViewController) {
let transition: CATransition = CATransition()
transition.duration = 0.35
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromRight
guard let containerView = view.window else { return }
@matnogaj
matnogaj / script.sh
Created April 26, 2016 04:38
Run script to display warnings in console in Xcode
TAGS="TODO:|FIXME:|WARNING:|FIXME"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@matnogaj
matnogaj / UILabel+SetAnimatedText.swift
Created April 18, 2016 10:34
Animated text for label
extension UILabel {
var animatedText: String {
set {
let animation = CATransition()
animation.duration = 0.3
animation.type = kCATransitionFade
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
layer.addAnimation(animation, forKey: "changeTextTransition")
text = newValue
@matnogaj
matnogaj / InterpolatedPath.swift
Created March 31, 2016 07:57
Path with different kinds of interpolation via given points.
import UIKit
class InterpolatedPath {
enum InterpolationType {
case Hermite
case CatmullRom
case BezierSpline
}
private (set) var closed: Bool
@matnogaj
matnogaj / Animator.swift
Last active May 18, 2016 09:18
Custom animator
//
// Animator.swift
//
// Created by Mateusz Nogaj on 26/03/16.
//
import UIKit
public func==(lhs: Animation, rhs: Animation) -> Bool {
return (lhs.name == rhs.name) && (lhs.view === rhs.view)
class RadialGradient:CALayer {
var startColor:UIColor!
var endColor:UIColor!
override init() {
super.init()
setNeedsDisplay()
}
required init?(coder aDecoder: NSCoder) {