Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
@samuelbeek
samuelbeek / Add and remove iCal events with your iOS app
Last active September 22, 2016 13:00
Add and remove iCal events with your iOS app.md
In order for this to work, you need to import Evenkit at the top of your file.
Then you can add the function setiCalEvent to your file and then you can simply use <code> [self setiCalEvent:true]; </code> or <code> [self setiCalEvent:false]; </code>. You don't need yo save any data inside your app to remove them later on, because the app does a search query.
@samuelbeek
samuelbeek / RandomColor.swift
Created June 15, 2016 10:08
Return random color (nice for debugging)
extension UIColor {
static func randomColor(alpha: CGFloat?) -> UIColor {
let red:CGFloat = CGFloat(drand48())
let green:CGFloat = CGFloat(drand48())
let blue:CGFloat = CGFloat(drand48())
return UIColor(red: red, green: green, blue: blue, alpha: alpha ?? 1.0)
}
}
@samuelbeek
samuelbeek / UIDeviceHelpers.swift
Created April 21, 2016 10:27
All devices in one big enum
import Foundation
public extension UIDevice {
public enum Model {
case iPodTouch5, iPodTouch6, iPhone4, iPhone4s, iPhone5, iPhone5c, iPhone5s, iPhone6, iPhone6Plus, iPhone6s, iPhone6sPlus, iPhoneSE, iPad2, iPad3, iPad4, iPadAir, iPadAir2, iPadMini, iPadMini2, iPadMini3, iPadMini4, iPadPro, AppleTV, Simulator, None
}
static var model: Model {
var systemInfo = utsname()
// remove navigation bar
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true
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
@samuelbeek
samuelbeek / TypingLabel.swift
Created December 9, 2015 15:36
Typewriting effect in swift
//
// TypingLabel.swift
//
// Created by Samuel Beek on 09/12/15.
// Copyright © 2015 Samuel Beek. All rights reserved.
//
import UIKit
import SwiftyTimer
@samuelbeek
samuelbeek / AppDelegate.swift
Created November 25, 2015 09:41
Set application wide navigation bar appereance
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().barStyle = UIBarStyle.Black
// rest of the didFinishLaunch stuff
}
@samuelbeek
samuelbeek / UISegmentedControlHelpers.swift
Last active November 18, 2015 11:01
Remove Segmented Control
// src: http://stackoverflow.com/questions/31651983/swift-how-to-remove-border-from-segmented-control
import UIKit
extension UISegmentedControl {
func removeBorders() {
setBackgroundImage(imageWithColor(backgroundColor!), forState: .Normal, barMetrics: .Default)
setBackgroundImage(imageWithColor(tintColor!), forState: .Selected, barMetrics: .Default)
setDividerImage(imageWithColor(UIColor.clearColor()), forLeftSegmentState: .Normal, rightSegmentState: .Normal, barMetrics: .Default)
}
@samuelbeek
samuelbeek / DeviceHelper.swift
Created November 18, 2015 10:27
Device distriction in Swift
//
// DeviceHelpers.swift
//
// Created by Samuel Beek on 08/10/15.
// Copyright © 2015 Samue Beek. All rights reserved.
//
import UIKit
struct Devices {
@samuelbeek
samuelbeek / Upload.swift
Last active November 10, 2015 11:16
Upload a file in a Multipart form
struct Uploader {
static let baseUrl = "YOUR API URL"
static func multipartBody(filePathKey: String, imageDataKey: NSData, boundary: String) -> NSData {
let body = NSMutableData();
let filename = "user-profile.jpg"
let mimetype = "image/jpg"
body.appendString("--\(boundary)\r\n")