Skip to content

Instantly share code, notes, and snippets.

View cmoulton's full-sized avatar

Christina Moulton cmoulton

View GitHub Profile
@IanKeen
IanKeen / EncodableDictionary.swift
Last active April 13, 2019 18:37
Type-safe Encodable Dictionary - useful for building quick dynamic Encodable packets
public struct EncodableDictionary {
typealias EncodingFunction = (inout KeyedEncodingContainer<AnyCodingKey>) throws -> Void
// MARK: - Private Properties
private var data: [String: Any] = [:]
private var encodings: [String: EncodingFunction] = [:]
// MARK: - Lifecycle
public init() { }
@cmoulton
cmoulton / Simple Alamofire Calls in Swift 4
Last active December 8, 2020 09:29
Simple Alamofire Calls in Swift 4
import Alamofire
func makeGetCallWithAlamofire() {
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1"
Alamofire.request(todoEndpoint)
.responseJSON { response in
// check for errors
guard response.result.error == nil else {
// got an error in getting the data, need to handle it
print("error calling GET on /todos/1")
@finder39
finder39 / Swift-MD5.swift
Last active March 20, 2018 13:37
Swift MD5
extension String {
func md5() -> String! {
let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.alloc(digestLen)
CC_MD5(str!, strLen, result)
var hash = NSMutableString()
@sawapi
sawapi / AppDelegate.swift
Last active October 25, 2023 09:26
[Swift] Push Notification
//
// AppDelegate.swift
// pushtest
//
// Created by sawapi on 2014/06/08.
// Copyright (c) 2014年 sawapi. All rights reserved.
//
// iOS8用
import UIKit
@Goos
Goos / gist:b31f6b21660aa092e6c2
Last active August 29, 2015 14:02
DateAdditions.swift
//
// DateAdditions.swift
// OMGSWIFT
//
// Created by Robin Goos on 03/06/14.
// Copyright (c) 2014 OMG. All rights reserved.
//
import Foundation
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {