Skip to content

Instantly share code, notes, and snippets.

View kevindelord's full-sized avatar

Delord Kévin kevindelord

View GitHub Profile
@kevindelord
kevindelord / etag
Last active August 10, 2023 13:58
How to integrate Etag in Swift
let API_HEADER_FIELD_NONE_MATCH : String = "If-None-Match"
let API_HEADER_FIELD_ETAG : String = "Etag"
let API_REQUEST_SUCCESS : Int = 200
func ETagForURL(urlString: String) -> String? {
// return the saved ETag value for the given URL
return NSUserDefaults.standardUserDefaults().objectForKey(urlString) as String?
}
@kevindelord
kevindelord / UIImage+Autoresize.h
Last active June 6, 2016 15:00
UIImage extension to automatically generate a valid UIImage on iPhone using an asset corresponding to the actual device screen size. If needed, this code will add the following image suffix: @2x, -568h@2x, -667h@2x, @3x.
//
// UIImage+Autoresize.h
// UIImage+Autoresize
//
// Created by kevin delord on 24/04/14.
// Copyright (c) 2014 Kevin Delord. All rights reserved.
//
// Full library and documentation here: https://github.com/kevindelord/UIImage-Autoresize
//
#ifndef UIImage_Autoresize_h__
@kevindelord
kevindelord / hockey_deploy.py
Created September 7, 2015 17:47
Build, archive and push a new iOS app version
#!/usr/bin/python
import sys
import argparse
import os
import subprocess
parser = argparse.ArgumentParser(description='Build, archive and push a new iOS app version!')
parser.add_argument('-w','--workspace', help='Path to workspace', required=True, default=None)
parser.add_argument('-s','--scheme', help='Scheme name to build', required=True, default=None)
// This very useful code parses a `.json` file using the library SwiftyJSON.
// Add this in a class, maybe in your Data Manager:
class func addDefaultEntities() {
if let file = NSBundle(forClass:AppDelegate.self).pathForResource(JSON.Constants.FileName, ofType: JSON.Constants.Type) {
if let data = NSData(contentsOfFile: file) {
for (index: String, bookJSON: JSON) in JSON(data:data) {
let dict = bookJSON.dictionaryObject
// do something with the dictionary
}