Skip to content

Instantly share code, notes, and snippets.

View krodak's full-sized avatar

Krzysztof Rodak krodak

View GitHub Profile
@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@krodak
krodak / SKMultilineLabel.swift
Created November 30, 2016 08:57 — forked from craiggrummitt/SKMultilineLabel.swift
Multi line label in Sprite Kit in Swift
//
// SKMultilineLabel.swift
//
// Created by Craig on 10/04/2015.
// Copyright (c) 2015 Interactive Coconut.
// MIT License, http://www.opensource.org/licenses/mit-license.php
//
/* USE:
(most component parameters have defaults)
let multiLabel = SKMultilineLabel(text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", labelWidth: 250, pos: CGPoint(x: size.width / 2, y: size.height / 2))
@krodak
krodak / UICollectionView+dequeue.swift
Last active March 17, 2016 16:46
UICollectionView+dequeue
extension UICollectionView {
public func dequeueReusableCell<T:UICollectionViewCell>(type: T.Type, indexPath: NSIndexPath) -> T {
let collectionCell : T
let cellIdentifier = String(T)
if let _ = NSBundle(forClass: T.classForCoder()).pathForResource(cellIdentifier, ofType:"nib") {
registerNib(UINib(nibName: cellIdentifier, bundle: nil), forCellWithReuseIdentifier: cellIdentifier)
collectionCell = dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as! T
}
class EventFeed: Hashable, Equatable {
var eventId = 0
var hashValue : Int { return eventId }
}
func ==(lhs: EventFeed, rhs: EventFeed) -> Bool {
return lhs.eventId == rhs.eventId
}
class PostUpload : EventFeed {
extension UIViewController {
func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if let nvc = self as? UINavigationController {
return nvc.topViewController!.supportedInterfaceOrientations()
} else {
return .Portrait
}
}
import Foundation
import UIKit
extension UINavigationController {
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if let visibleViewController = visibleViewController {
return visibleViewController.supportedInterfaceOrientations()
} else if let topViewController = topViewController {
@krodak
krodak / UITableView_universalDequeue.swift
Last active January 19, 2016 08:26
Safely dequeue any `UITableViewCell`'s subclass instance with assumption that .xib name is the same as subclass name.
extension UITableView {
public func dequeueReusableCell<T:UITableViewCell>(type: T.Type) -> T {
let tableCell : T
let cellIdentifier = String(T)
if let cell = self.dequeueReusableCellWithIdentifier(cellIdentifier) as? T {
tableCell = cell
} else if let _ = NSBundle(forClass: T.classForCoder()).pathForResource(cellIdentifier, ofType:"nib") {
self.registerNib(UINib(nibName: cellIdentifier, bundle: nil), forCellReuseIdentifier: cellIdentifier)
@krodak
krodak / UIViewController+TabBarAnimations
Last active March 3, 2018 19:15
UIViewController extension for hidding UITabBarController
import UIKit
extension UIViewController {
func setTabBarVisible(visible:Bool, animated:Bool) {
//* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
// bail if the current state matches the desired state
if (tabBarIsVisible() == visible) { return }