This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bundle-Decodable.swift | |
// Usage (example): let users = Bundle.main.decode([User].self, from: "users.json") | |
import Foundation | |
extension Bundle { | |
func decode<T: Decodable>(_ type: T.Type, from file: String, dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate, keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) -> T { | |
guard let url = self.url(forResource: file, withExtension: nil) else { | |
fatalError("Failed to locate \(file) in bundle.") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Row: View { | |
let text: String | |
let showDivider: Bool | |
var body: some View { | |
VStack(alignment: .leading) { | |
Text(text) | |
.padding(showDivider ? [.leading, .top] : [.leading, .top, .bottom]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct GenericUIViewRepresentable<ViewType>: UIViewRepresentable where ViewType: UIView { | |
let factory: (Context) -> ViewType | |
func makeUIView(context: Context) -> ViewType { | |
factory(context) | |
} | |
func updateUIView(_ uiView: ViewType, context: Context) {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct GenericUIViewControllerRepresentable<ViewControllerType>: UIViewControllerRepresentable | |
where ViewControllerType: UIViewController { | |
let factory: (Context) -> ViewControllerType | |
func makeUIViewController(context: Context) -> ViewControllerType { | |
factory(context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<array/> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Data { | |
func decoded<T: Decodable>( | |
as type: T.Type = T.self, | |
handledOn resultQueue: DispatchQueue = .main, | |
handler: @escaping (Result<T, Error>) -> Void | |
) { | |
let queue = DispatchQueue(label: "com.myapp.decoding") | |
let decoder = JSONDecoder() | |
queue.async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Use this when you need to have working playground and project: see more at https://www.twilio.com/blog/intro-to-markov-models-with-swift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIFont { | |
class func printAllFonts() { | |
UIFont.familyNames().forEach { family in | |
UIFont.fontNamesForFamilyName(family).forEach { font in | |
print(font) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple check if connected to internet | |
func isConnected() -> Bool { | |
// we need SCNetworkReachability object | |
guard let reachability = SCNetworkReachabilityCreateWithName(nil, "https://inloop-contacts.appspot.com/_ah/api/contactendpoint/v1/contact") else { return false } | |
// and flags | |
var flags = SCNetworkReachabilityFlags() | |
// read the "flags" into flags (via SCNetworkReachabilityGetFlags) | |
SCNetworkReachabilityGetFlags(reachability, &flags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SharePromptView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
createSubviews() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
createSubviews() | |
} | |
func createSubviews() { |
NewerOlder