Skip to content

Instantly share code, notes, and snippets.

View Bradysm's full-sized avatar
🎯
Focusing

Brady Murphy Bradysm

🎯
Focusing
View GitHub Profile
/**
Class used to load URL images asynchronously
*/
final class ImageLoader: ObservableObject {
@Published public var imageData:Data // data that will get published when loaded
init(url imageUrl: String) {
self.imageData = Data() // assign the value
// call the API and try to get the data
//
// Modal.swift
// TheRealYou
//
// Created by brady murphy on 11/28/19.
// Copyright © 2019 Brady Murphy. All rights reserved.
//
import SwiftUI
//
// ExampleCard.swift
// PopQuiz WatchKit Extension
//
// Created by brady murphy on 11/30/19.
// Copyright © 2019 Apple. All rights reserved.
//
import SwiftUI
@Bradysm
Bradysm / FontNameGenerator.swift
Created March 28, 2020 18:26
Font name generator
// place this function in a .onAppear() lifecycle call on your root view
// credit to apple https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app
// Created By: Brady Murphy
func getCustomFontNames() {
// get each of the font families
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
// print array of names
print("Family: \(family) Font names: \(names)")
@Bradysm
Bradysm / FontNameManager.swift
Created March 28, 2020 18:52
Manager struct to ensure encapsulation of font names
// FontNameManager created by Brady Murphy
struct FontNameManager {
//MARK: name of font family
struct Montserrat {
static let light = "Montserrat-Light"
static let regular = "Montserrat-Regular"
// add rest of the font style names
}
@Bradysm
Bradysm / CustomFont.swift
Last active March 28, 2020 18:53
Custom font example
// Created by Brady Murphy
import SwiftUI
// create the custom font
let headerFont = Font.custom(FontNameManager.Montserrat.semiBold, size: 28)
struct ExampleView: View {
var body: some View {
// using the custom font to modify the text view
@Bradysm
Bradysm / ColorManagerExample.swift
Last active July 25, 2020 14:12
Example of using the color manager within your application
import SwiftUI
struct SpotifyText: View {
var body: some View {
Text("Spotify Green")
.foregroundColor(ColorManager.spotifyGreen)
}
}
struct WithDependencyInjection {
var module: Module
// inject the dependency through the initializer
// to explicitly show the dependency on Module
init(module: Module) {
self.module = module
}
}
struct WithoutDependencyInjection {
var module: Module
init() {
// creating the module ourselves in the init
// without stating the dependency on "Module"
self.module = Module()
}
}
struct WithDependencyInjection {
var module: Module
// inject the dependency through the initializer
// to explicitly show the dependency on Module
init(module: Module) {
self.module = module
}
}