Skip to content

Instantly share code, notes, and snippets.

{
"808": {
"vod": [
"Documentary",
"Music"
],
"iva": [
"Documentary",
"Musical"
]
@ejmartin504
ejmartin504 / AsyncLocalStorage.swift
Created March 19, 2018 21:23
Demonstration of fetching data from React Native AsyncLocalStorage
// Since AsyncLocalStorage API is not exposed to native code, we have to grab the data ourselves.
// If you have been able to get Cocoapods use_frameworks! to work, you can `import React`
// Else make sure to include the following in your brindging header:
// #import <React/RCTAsyncLocalStorage.h>
import Foundation
class CacheManager {
let storageLocation = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("RCTAsyncLocalStorage_V1")
@ejmartin504
ejmartin504 / UITextView+HTML.swift
Created March 13, 2017 18:57
Load HTML String into UITextView
extension UITextView {
func load(HTMLString: String) {
guard let htmlData = HTMLString.data(using: .utf8) else { return }
let options: [String: Any] = [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue
]
let strNative = try! NSMutableAttributedString(data: htmlData, options: options, documentAttributes: nil)
@ejmartin504
ejmartin504 / StackableWebView.swift
Created March 13, 2017 16:58
WKWebView that resizes itself
import Foundation
import WebKit
// See https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html for more details.
private var observerContext = 0
class StackableWebView: WKWebView {
// Keep track of height which will change when the view is loaded.
var webViewHeight: CGFloat = 0.0
@ejmartin504
ejmartin504 / UIView+instantiateFromNib.swift
Created March 13, 2017 16:56
Load view from a nib file
import UIKit
public extension UIView {
public class func instantiateFromNib<T: UIView>(viewType: T.Type) -> T {
return Bundle.main.loadNibNamed(String(describing: viewType), owner: nil, options: nil)!.first as! T
}
public class func instantiateFromNib() -> Self {
return instantiateFromNib(viewType: self)
}