Skip to content

Instantly share code, notes, and snippets.

View stinger's full-sized avatar

Ilian Konchev stinger

View GitHub Profile
@stinger
stinger / MKMapView+Extensions.swift
Last active November 17, 2016 14:23
Swift 3: MKMapView Helpers
import UIKit
import MapKit
extension MKMapView {
func showLocation(at coordinate: CLLocationCoordinate2D) {
self.removeOverlays(self.overlays)
self.removeAnnotations(self.annotations)
let annotation = MKPointAnnotation()
@stinger
stinger / gist:19bb9b9940c2be828b3703429c5ddeec
Created December 12, 2016 07:58 — forked from maxkandler/gist:5233150
Hide the iTerm2 Dock icon.
/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
@stinger
stinger / RxSwiftMVVMViewSinks.swift
Created January 2, 2017 15:05
RxSwift MVVM view sinks
class MyCustomView : UIView {
var sink : AnyObserver<SomeComplexStructure> {
return AnyObserver { [weak self] event in
switch event {
case .next(let data):
self?.something.text = data.property.text
break
case .error(let error):
self?.backgroundColor = .red
#set the shell to /bin/sh
TAGS="TODO:|FIXME:"
find "${SRCROOT}" \( -name "*.swift" \) -type f -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
var fetchedResultsProcessingOperations: [NSBlockOperation] = []
private func addFetchedResultsProcessingBlock(processingBlock:(Void)->Void) {
fetchedResultsProcessingOperations.append(NSBlockOperation(block: processingBlock))
}
func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
switch type {
case .Insert:
@stinger
stinger / Swift3URLComponent.swift
Created June 21, 2016 11:03
Swift 3: Using URLComponents
//: # Swift 3: Using URLComponents
import Foundation
//: ### Compose the componens
var url = URLComponents()
url.scheme = "http"
url.host = "google.com"
//: ### Pass the query string parameters
url.queryItems = [
URLQueryItem(name: "test", value: "data"),
@stinger
stinger / RxCollectionViewSectionedAnimatedDataSourceExample.swift
Created March 28, 2017 09:53
RxCollectionViewSectionedAnimatedDataSource example with multiple cells types
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
class ViewController: BaseCollectionViewController {
...
typealias Section = AnimatableSectionModel<String, CellStyle>
@stinger
stinger / InfinityLoader.swift
Created March 23, 2018 08:18
InfinityLoader swift demo
import UIKit
import PlaygroundSupport
public class InfinityLoader: UIView {
let anim = CAAnimationGroup()
//// Drawing Methods
lazy var path: UIBezierPath = {
@stinger
stinger / Swift3GCDURLSessionDataTask.swift
Last active March 26, 2018 21:36
Swift 3: GCD and URLSessionDataTask with a completionHandler
//: # Swift 3: CGD and URLSessionDataTask
import Foundation
import PlaygroundSupport
//: ### Create background queue
let queue = DispatchQueue.global(qos: .background)
//: ### Computed variable
var time:DispatchTime! {