Skip to content

Instantly share code, notes, and snippets.

View samuelbeek's full-sized avatar

Samuel Beek samuelbeek

View GitHub Profile
@samuelbeek
samuelbeek / Platform.swift
Created November 24, 2015 12:23
Detect if Simulator is used in Swift
struct Platform
{
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true
#endif
return isSim
}()
}
@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 / StringContainsNumber.swift
Created November 17, 2015 15:30
Check if string contains number or whitespace
import Foundation
extension String {
func containsNumbers() -> Bool {
// check if there's a range for a number
let range = self.rangeOfCharacterFromSet(.decimalDigitCharacterSet())
@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")
[
{
"code": "AD",
"emoji": "🇦🇩",
"unicode": "U+1F1E6 U+1F1E9",
"name": "Andorra",
"title": "flag for Andorra"
},
{
"code": "AE",
@samuelbeek
samuelbeek / Analytics.swift
Created October 21, 2015 09:07
Google Analytics Helper (Work In Progress)
//
// Analytics.swift
// Instant
//
// Created by Samuel Beek on 21/10/15.
// Copyright © 2015 Samue Beek. All rights reserved.
//
struct Analytics {
@samuelbeek
samuelbeek / DeviceHelper.swift
Created October 8, 2015 10:46
detect iOS devices
// example if(Devices.iPhone4) { view.alpha = 0 }
struct Devices {
static let iPhone4 = UIScreen.mainScreen().bounds.size.height == 480.0
static let iPhone5 = UIScreen.mainScreen().bounds.size.height == 568.0
static let iPhone6 = UIScreen.mainScreen().bounds.size.height == 667.0
static let iPhone6plus = UIScreen.mainScreen().bounds.size.height == 736.0
}
//
// ColorHelper.swift
// Wildcard
//
// Created by Samuel Beek on 24/06/15.
// Copyright (c) 2015 Wildcard. All rights reserved.
//
import UIKit
@samuelbeek
samuelbeek / Local.swift
Last active August 29, 2015 14:24
Awesome local storage usage with Realm in Swift
// this code does work, but since it's from a 'secret' project, I can't display
// the other code. Implement it in your own project, it'll work.
//
// LOCAL.swift
// Wildcard
//
// Created by Samuel Beek on 08/07/15.
// Copyright (c) 2015 Wildcard. All rights reserved.
//