This file contains hidden or 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
//Quick five minute snippet to generate a promo code based on a given format. | |
//C = Character, N = Number, A = Alphanumeric. | |
//When I get some time, I'll put more thought into making a better algorithm | |
func generatePromoCode(using format: String) -> String { | |
var returnCode: String = "" | |
let alphabet = (65...90).map({Character(UnicodeScalar($0))}) | |
let numbers = (48...57).map({Character(UnicodeScalar($0))}) | |
let alphanumeric = alphabet + numbers |
This file contains hidden or 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
final class ObservableObject<T> { | |
var value: T { | |
didSet { | |
listener?(value) | |
} | |
} | |
private var listener: ((T) -> Void)? | |
init(_ value: T) { |
This file contains hidden or 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
//Taken from StackOverflow. I've not tested this thoroughly. Check on actual devices before using in production code | |
func modelIdentifier() -> String { | |
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier } | |
var sysinfo = utsname() | |
uname(&sysinfo) // ignore return value | |
return String(bytes: Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters) | |
} |
This file contains hidden or 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
var connected: Bool { | |
return UIDevice.current.batteryState != .unplugged | |
} | |
var batteryLevel: Int { | |
UIDevice.current.isBatteryMonitoringEnabled = true | |
let level: Int = Int(UIDevice.current.batteryLevel * 100) | |
return level | |
} |
This file contains hidden or 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
// **** NOTE **** | |
// It turns out that Apple has an API for this: UnitTemperature | |
// More information at: https://developer.apple.com/documentation/foundation/unittemperature | |
// Convert temperature to Fahrenheit, Celcius and Kelvin | |
// Note: This was quickly put together and verifying the results is warranted. | |
// FIXME: Kelvin converts to celcius, which will most assuredly produce incorrect | |
// results, as no attempt was made to determine what unit is coming in. |
This file contains hidden or 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
//Code comes from https://www.youtube.com/watch?v=I1imChxYClk&list=PLEVREFF3xBv4MviDGwlFz-onZ08TWrNjD | |
//Will need to make slight mods to make work with actual project (i.e. SimpleView_Preview needs renamed) | |
//PreviewViewController | |
#if canImport(SwiftUI) && DEBUG | |
import SwiftUI | |
struct UIViewControllerPreview<ViewController: UIViewController> : UIViewControllerRepresentable { | |
let viewController: ViewController | |
This file contains hidden or 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
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' | |
killall Dock |
This file contains hidden or 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 Array { | |
func toString() -> String { | |
var result: String = "" | |
for element in self { | |
result = "\(result),\(element)" | |
} | |
return String(result.dropFirst()) | |
} |
This file contains hidden or 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 | |
import WebKit | |
class WebViewer: UIViewController, WKUIDelegate { | |
var webView = WKWebView() | |
var filename: String = "" | |
var fileUrl: URL? | |
override func loadView() { |
This file contains hidden or 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 Cocoa | |
import Foundation | |
import WebKit | |
@main | |
class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate { | |
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength) | |
let popover = NSPopover() | |
NewerOlder