Skip to content

Instantly share code, notes, and snippets.

View celian-m's full-sized avatar

celian celian-m

  • MyStudioFactory
  • Paris
View GitHub Profile
@celian-m
celian-m / SessionDelegate.swift
Created January 13, 2017 16:33
Perform client side certificate check
import Foundation
public struct IdentityAndTrust {
public var identityRef:SecIdentity
public var trust:SecTrust
public var certArray:NSArray
}
public func extractIdentity(certData:NSData, certPassword:String) -> IdentityAndTrust {
@celian-m
celian-m / Async.swift
Last active January 13, 2017 10:39
Use async task in iOS Playground
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.finishExecution()
@celian-m
celian-m / CustomLayout.swift
Created December 8, 2016 15:40
CustomLayout for CollectionViewLayout
class CustomLayout : UICollectionViewFlowLayout {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.itemSize = CGSize(width: itemWidth, height: itemWidth)
self.scrollDirection = .horizontal
self.minimumLineSpacing = 0
@celian-m
celian-m / ImageLoader.swift
Last active June 20, 2017 08:01
ImageLoader
import UIKit
struct ImageCache {
private var cache : [URL : Data] = [:]
static var worker : ImageCache = {
return ImageCache()
}()
static func addToCache(url : URL, data : Data) {
@celian-m
celian-m / FileSave.swift
Created November 16, 2016 09:05
Save WS Call to file [Swift 2.3]
private func saveToFile(string : String, url : String, method : String) {
guard let dir = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).last else { return }
guard let fileurl = dir.URLByAppendingPathComponent("log.txt") else { return }
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd' 'HH:mm:ssZZZZZ"
let string = dateFormatter.stringFromDate(NSDate()) + " [" + method + "] " + url + "\n" + string + "\n"
let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
if NSFileManager.defaultManager().fileExistsAtPath(fileurl.path!) {
@celian-m
celian-m / SuperViewController.swift
Created June 17, 2016 08:24
Super View controller for iOS swift apps
//
// SuperViewController.swift
// Mouce
//
// Created by Célian MOUTAFIS on 15/06/2016.
// Copyright © 2016 Célian MOUTAFIS. All rights reserved.
//
import Foundation
import UIKit
@celian-m
celian-m / CoreDataManager.swift
Last active May 10, 2016 12:20
Core Data Manager for Swift usage
//
// CoreDataController.swift
//
//
// Created by Célian MOUTAFIS on 26/04/2016.
// Copyright © 2016 mouce. All rights reserved.
//
import Foundation
@celian-m
celian-m / CurrentDevice.swift
Created April 13, 2016 07:30
Check Device Model in Swift
public extension UIDevice {
var modelName: String {
#if (arch(i386) || arch(x86_64)) && os(iOS)
let DEVICE_IS_SIMULATOR = true
#else
let DEVICE_IS_SIMULATOR = false
#endif
var machineString : String = ""
@celian-m
celian-m / debugQuickLookObject.md
Last active March 3, 2016 14:09
iOS debugQuickLookObject

#Visual Debuging# If you are borred to use po myObject to check the content of your objects, you may use debugQuickLookObject, an XCode hidden gem.

Assuming your object is a subclass of NSObject

- (id)debugQuickLookObject {
    UIImage* img = [UIImage imageNamed:self.productThumbImage];
    UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
 view.image = img;
@celian-m
celian-m / iOS_Notifications.md
Last active February 29, 2016 13:37
Register for iOS Push Notifications, iOS7 and above

#Registering

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//Your code...

//Check if OS is Version 7
  if (![[UIApplication sharedApplication]
          respondsToSelector:@selector(registerUserNotificationSettings:)]) {