Skip to content

Instantly share code, notes, and snippets.

View popmedic's full-sized avatar

Popmedic popmedic

View GitHub Profile
@popmedic
popmedic / Logger.swift
Last active July 13, 2018 15:02
LoggerTextView is a subclass of UITextView that can be used as a log for QA of a project. Uses https://gist.github.com/popmedic/291af6918ac4f0a43d187e2379484c64
import UIKit
let __kDefaultColorError = UIColor.redColor()
let __kDefaultColorSuccess = UIColor.greenColor()
let __kDefaultColor = UIColor.whiteColor()
let __kDefaultColorBackground = UIColor.blackColor()
let __kDefaultFont = UIFont(name: "Menlo-Bold", size: 12.0)!
let __kLoggerTextFieldListenerName = "com.webroot.control.LoggerTextField"
@popmedic
popmedic / PickerTextField.swift
Last active July 13, 2018 15:01
PickerTextField - Use PickerTextField when you want a list of choices in a UIPickerView displayed in place of the key board.
import UIKit
/**
PickerTextField - Use PickerTextField when you want a list of choices in a UIPickerView displayed in place of the key board.
- Note:
Set it up by setting the choices to an array of strings. These are the strings that will show up in the UIPickerView for the key board.
- Note:
You can set a block for onSelected for action when something is selected.
- Note:
The selectedTimeOut property can be set for the amount of time to wait after something is selected before ending the edit.
@popmedic
popmedic / ColorPickerTextField.swift
Last active July 13, 2018 15:00
ColorPickerTextField - Use ColorPickerTextField when you want to show a list of colors in a UIPickerView when editing text field.
import UIKit
public class ColorPickerTextField: PickerTextField {
public var colorChoices = [
UIColor.blackColor(),
UIColor.blueColor(),
UIColor.brownColor(),
UIColor.darkGrayColor(),
UIColor.cyanColor(),
UIColor.grayColor(),
import UIKit
public class FontPickerTextField: PickerTextField {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
for familyName in UIFont.familyNames() {
self.choices.appendContentsOf(UIFont.fontNamesForFamilyName(familyName))
}
self.choices = self.choices.sort()
self.text = self.choices[0]
@popmedic
popmedic / tldlist.swift
Last active March 7, 2021 10:26
a class with a static member with all top-level-domains
class TLDList {
static let tlds = [
"*.aaa",
"*.aarp",
"*.abarth",
"*.abb",
"*.abbott",
"*.abbvie",
"*.abc",
"*.able",
@popmedic
popmedic / Extension.swift
Last active July 13, 2018 14:58
(Swift 4.x) An extension to UIImage to load from a remote URL and an extension to UIImageView to load its image using the UIImage extension.
import UIKit
extension UIImage {
/// will load an image from a remote URL
/// - parameter fromURL: url to load from
/// - parameter completionHandler: completion handler for when the image is done loading.
/// - parameter image: UIImage? that was retrieved, or nil on error
/// - parameter error: LocalizedError? that is nil on success, or an error message on failure.
/// example
/// ```
import UIKit
/**
Class to make "Toast," like in Android, for iOS in Swift 4.x.
example:
```
Toast.backgroundColor = UIColor.init(red: 0.0, green: 1.0, blue: 0.0, alpha: 0.6)
Toast.textColor = UIColor.init(red: 1.0, green: 0.0, blue: 0.0, alpha: 0.6)
Toast.textAlignment = .center
Toast.font = UIFont.systemFont(ofSize: 14.0)
import UIKit
protocol Invokable {
var order: Int { get }
func invoke()
}
class A: Invokable {
var order = 0
func invoke() { print("A") }
@popmedic
popmedic / plistVjsonToDict.swift
Last active April 25, 2020 17:40
Plist vs. JSON for converting Encodable implementation to Any (Dictionary)
import Foundation
struct LotsOfStuff: Codable {
let x: Int
let y: Int
let z: Double
let a: [String]
let b: String
let c: String
let less: LessStuff