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 { | |
/// 1) | |
/// Function that will register a new `UIFont` from the provided bundle usign Core Graphics. If the font can't be registered a fatal error is thrown. We throw a fatal error because we want to know right away if our font's don't load. Maybe a more appropriate way is to throw `Error`'s but this removes a lot of optional unwrapping code when using the font's as they can be used as non optional values. | |
/// | |
/// - Parameters: | |
/// - bundle: The bundle the font file lives in. Defaults to `Bundle.main` | |
/// - fontName: The name of the font file. | |
/// - fontExtension: The extension of the font file | |
static public func registerFont(bundle: Bundle? = Bundle.main, fontName: String, fontExtension: String) { | |
guard let fontURL = bundle?.url(forResource: fontName, withExtension: fontExtension) else { |
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 UIKit | |
/// Struct that lets you access the linear icons in code. | |
struct IconFont { | |
//MARK: Properties | |
/// The name of the IcoMoon-Free file used ot register the font. | |
let iconFontName = "IcoMoon-Free" | |
/// Upstanding up arrow | |
let arrow_up = "\u{ea3a}" |
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 UIKit | |
class RootViewController: UIViewController { | |
//MARK: Properties | |
let label = UILabel(frame: .zero) | |
//MARK: Lifecycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
//Set up label |
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
/// Function that will take a unicode character from the Linear Icon set and turn it into a `UIImage` | |
/// | |
/// - Parameters: | |
/// - unicode: The unicode character (Icon) to turn into an image | |
/// - color: The color you want the Icon to be | |
/// - size: The size you want the Icon to be | |
/// - Returns: Gives you a crisp `UIImage` | |
public func image(fromUnicode unicode: String, color: UIColor, size: CGFloat) -> UIImage { | |
let attributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: self.iconFont(size), NSAttributedString.Key.backgroundColor: UIColor.clear, NSAttributedString.Key.foregroundColor: color] | |
let S = CGSize(width: size, height: size) |
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 Apollo | |
struct ApolloController { | |
//MARK: Properties | |
//The Apollo graph QL Root object | |
var apollo: ApolloClient? | |
//MARK: Init | |
init() { |
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
@UIApplicationMain | |
class AppDelegate: UIResponder { | |
/// The window object. | |
var window: UIWindow? | |
/// The Apollo Controller. | |
lazy var apolloController = ApolloController() | |
} | |
extension AppDelegate: UIApplicationDelegate { |
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
protocol ApolloControllerAvailable { | |
var apolloController: ApolloController? { get } | |
} | |
extension ApolloControllerAvailable { | |
var apolloController: ApolloController? { | |
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { | |
return nil | |
} | |
return appDelegate.apolloController |
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 LoginViewController: UIViewController, ApolloControllerAvailable { | |
//MARK: Properties | |
//MARK: Lifecycle | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
//We have access!! | |
self.apolloController | |
} | |
} |
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
/** Cosine similarity **/ | |
private func cosineSim(A: [Double], B: [Double]) -> Double { | |
return dot(A: A, B: B) / (magnitude(A: A) * magnitude(A: B)) | |
} | |
/** Dot Product **/ | |
private func dot(A: [Double], B: [Double]) -> Double { | |
var x: Double = 0 | |
for i in 0...A.count-1 { | |
x += A[i] * B[i] |
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
func euclideanDistance(first: [Double], second: [Double]) -> Double { | |
guard first.count == second.count else { | |
fatalError("Vector space is not the same") | |
} | |
var result: Double = 0 | |
for i in 0..<first.count { | |
result += pow(first[i] - second[i], 2.0) | |
} | |
return sqrt(result) | |
} |
OlderNewer