Skip to content

Instantly share code, notes, and snippets.

@barrault01
barrault01 / showtouch
Created July 30, 2018 13:13
Show touch highlights on iOS Simulator
defaults write com.apple.iphonesimulator ShowSingleTouches 1
@barrault01
barrault01 / BasicPlayground.swift
Last active November 19, 2018 10:44
Basic Playground with custom liveView
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .lightGray
let label = UILabel()
label.numberOfLines = 0
let usingNonBreakingSpace = UILabel()
usingNonBreakingSpace.numberOfLines = 0
usingNonBreakingSpace.frame = CGRect(x: 90, y: 300, width: 220, height: 60)
usingNonBreakingSpace.text = "My phone number is (555)\u{00a0}123–4567"
usingNonBreakingSpace.textColor = .black
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .lightGray
let label = UILabel()
label.numberOfLines = 0
@barrault01
barrault01 / GetCookies.swift
Created December 3, 2018 10:32
Get cookies form WKWebview
webview.configuration.websiteDataStore.httpCookieStore.getAllCookies { (cookies) in
print(cookies)
}
extension HTTPCookie {
func save(cookieProperties: [HTTPCookiePropertyKey : Any]) -> Data {
let data = NSKeyedArchiver.archivedData(withRootObject: cookieProperties)
return data
}
func arquive() -> Data? {
guard let properties = self.properties else {
return nil
}
extension HTTPCookie {
static fileprivate func loadCookieProperties(from data: Data) -> [HTTPCookiePropertyKey : Any]? {
let unarchivedDictionary = NSKeyedUnarchiver.unarchiveObject(with: data)
return unarchivedDictionary as? [HTTPCookiePropertyKey : Any]
}
static func loadCookie(using data: Data?) -> HTTPCookie? {
guard let data = data,
let properties = loadCookieProperties(from: data) else {
return nil
@barrault01
barrault01 / ReactViewControllerPresenter.swift
Created December 17, 2018 11:46
swift protocol to present a react native view
import UIKit
public protocol ReactPresenter {
func presentReactViewController(moduleName: String?, jsFileName: String?,bundle: Bundle? , isDebug: Bool, props: [String: Any]?, hidesBottomBarWhenPushed: Bool, showNavigationBar: Bool)
func showReactViewController(moduleName: String?, jsFileName: String?,bundle: Bundle? , isDebug: Bool, props: [String: Any]? , hidesBottomBarWhenPushed: Bool, showNavigationBar: Bool)
func presenterViewController() -> UIViewController
}
extension ReactPresenter where Self: UIViewController {
@barrault01
barrault01 / ReactViewController.swift
Last active December 31, 2018 13:37
A UIViewController that present React Native application
import UIKit
import React
@objc(ReactViewController)
public class ReactViewController: UIViewController {
var moduleName: String = ""
var jsFileName: String = ""
var isDebug: Bool = false
var showNavigationBar: Bool = true
@barrault01
barrault01 / SwiftReactModuleExports.m
Created December 17, 2018 11:49
File that add export the dismissReactView function and the ReactViewController module to react native
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(ReactViewController, NSObject)
RCT_EXTERN_METHOD(dismissReactView)
@end