Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
class Dynamic<T> {
typealias Listener = T -> Void
var listener: Listener?
func bind(listener: Listener?) {
self.listener = listener
}
func bindAndFire(listener: Listener?) {
self.listener = listener
@wildthink
wildthink / ActionTrampoline.swift
Last active December 5, 2019 21:08
ActionTrampoline - Use Swift blocks for your Control actions
//
// ActionTrampoline.swift
// Swift 3
//
// Created by Jason Jobe on 3/17/16.
// Copyright © 2016 WildThink. All rights reserved.
//
// https://gist.githubusercontent.com/wildthink/677308084ab364044c76/raw/f713efca9ec6ca9b56c4405bd82ae33b1db98ec7/ActionTrampoline.swift
//
// Kudos (again) to Mike Ash!
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = false
controller.searchBar.barStyle = .Black
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
@steipete
steipete / FilterScriptPhase.sh
Created April 27, 2015 16:25
This filter script phase is required to remove unused architectures from your application, which would be flagged as issue during upload to the Apple AppStore. Read more at http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
@sohelsd
sohelsd / UIActivity WhatsApp
Last active January 21, 2023 23:13
WhatsApp Swift UIActivityViewController Custom UIActivity
How to add WhatsApp to UIActivityViewController?
Drop the Whatsapp.swift file in your project.
Initialize the controller as described in ViewController.swift
@Ziewvater
Ziewvater / GfycatHandler
Created March 14, 2015 17:00
Uploading to Gfycat using AFNetworking in Swift
import UIKit
let GfycatPOSTURL = "https://gifaffe.s3.amazonaws.com/"
let GfycatPolicy = "eyAiZXhwaXJhdGlvbiI6ICIyMDIwLTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICAgICAgICAgICAiY29uZGl0aW9ucyI6IFsKICAgICAgICAgICAgeyJidWNrZXQiOiAiZ2lmYWZmZSJ9LAogICAgICAgICAgICBbInN0YXJ0cy13aXRoIiwgIiRrZXkiLCAiIl0sCiAgICAgICAgICAgIHsiYWNsIjogInByaXZhdGUifSwKCSAgICB7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6ICIyMDAifSwKICAgICAgICAgICAgWyJzdGFydHMtd2l0aCIsICIkQ29udGVudC1UeXBlIiwgIiJdLAogICAgICAgICAgICBbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwgMCwgNTI0Mjg4MDAwXQogICAgICAgICAgICBdCiAgICAgICAgICB9"
let GfycatAWSAccessKeyId = "AKIAIT4VU4B7G2LQYKZQ"
let GfycatSignature = "mk9t/U/wRN4/uU01mXfeTe2Kcoc="
let GfycatTranscodeURL = "http://upload.gfycat.com/transcode/"
class GfycatHandler: NSObject {
@andreamazz
andreamazz / ViewController.swift
Created January 12, 2015 09:18
Quick setup of AMPopTip with Swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var cardView: UIView!
var popTip = AMPopTip()
override func viewDidLoad() {
super.viewDidLoad()
}
@westerlund
westerlund / gif.swift
Created December 22, 2014 17:07
Create an animated gif in swift
func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) -> ()) {
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]]
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]]
let documentsDirectory = NSTemporaryDirectory()
let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif")
if let url = url {
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil)
CGImageDestinationSetProperties(destination, fileProperties)
@siberianisaev
siberianisaev / UINavigationBar+Height.swift
Last active October 30, 2019 07:57
Change height of UINavigationBar
import Foundation
private var AssociatedObjectHandle: UInt8 = 0
extension UINavigationBar {
var height: CGFloat {
get {
if let h = objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat {
@seyhunak
seyhunak / local_notification.swift
Created July 16, 2014 14:47
Local Notification - Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
// Override point for customization after application launch.
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert |
UIUserNotificationType.Badge, categories: nil))
return true
}