Skip to content

Instantly share code, notes, and snippets.

View jimbrayrcp's full-sized avatar
😀

Jim Bray jimbrayrcp

😀
  • San Antonio, Texas
View GitHub Profile
@jimbrayrcp
jimbrayrcp / Error Print.swift
Last active May 6, 2020 16:08
Swift 5: iOS: 13.1 Swift will print out the error with a description
print("ERROR: \(error.localizedDescription)")
@jimbrayrcp
jimbrayrcp / pList Buddie - (hide dock icon).sh
Last active May 6, 2020 14:11
Will hide the Dock icon of an application you want to run in the background. However, after applying, started seeing errors during boot time with the application. To Undo: https://gist.github.com/a02339fd11bc31fd3ddd78c322b17516
/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/[application name].app/Contents/Info.plist
@jimbrayrcp
jimbrayrcp / pList Buddie - (show dock icon).sh
Created May 6, 2020 14:10
Will show the Dock icon of an application which was previously set to run in the background. Basically an Undo of : https://gist.github.com/8399c80626b769d54ddcecf800c53ce8
/usr/libexec/PlistBuddy -c 'Delete :LSUIElement' /Applications/[AppName].app/Contents/Info.plist
@jimbrayrcp
jimbrayrcp / Title & Prompt (view).swift
Last active May 6, 2020 16:08
Swift 5: iOS: 13.1 Adds Title and Prompt to the ViewController with Navigation controller add to: override func viewDidLoad() {
self.navigationItem.title = "TITLE"
self.navigationItem.prompt = "Prompt"
@jimbrayrcp
jimbrayrcp / String to Integer (extension).swift
Last active May 6, 2020 16:07
Swift 5: iOS: 13.1 Converts String to Integer, Double, Float, Bool Use : let myString = "51.55522222222" print(myString.toInteger() ?? "") print(myString.toDouble() ?? "") print(myString.toFloat() ?? "") print(myString.toBool() ?? "")
import Foundation
// ...
extension String {
// Converts String to Integer
public func toInteger() -> Int? {
if let num = NumberFormatter().number(from: self) {
return num.intValue
} else {
return nil
}
@jimbrayrcp
jimbrayrcp / Date Formatter (extension).swift
Last active May 6, 2020 16:06
Swift 5: iOS: 13.1 Date formatter and converter: Converts: dateString to Date dateString to Formatted Date String date to Formatted date string
import Foundation
// USE:
var dateString = "14.05.2020T10:30:10"
let dateFormat = DateFormatter(format: "dd.MM.yyyy'T'HH:mm:ss")
let dateFormat1 = DateFormatter(format: "MM/dd/yyyy '@' HH:mm")
let date = Date()
print("date String -> toDate: \(dateString.toDate(dateFormatter: dateFormat)!)")
print("date String -> toDateString: \(dateString.toDateString(dateFormatter: dateFormat, outputFormat: "MM/dd/yy")!)")
@jimbrayrcp
jimbrayrcp / Keyboard Dismiss.swift
Last active May 6, 2020 16:06
Works in Swift 5: iOS: 13.1 Dismiss a keyboard when tapping outside of field
// ************************************
// ADD TO VIEW DID LOAD
// ------------------------------------
let tap: UITapGestureRecognizer = UITapGestureRecognizer(
target: self,
action: #selector(UIInputViewController.dismissKeyboard))
//Uncomment to prevent interference of cancel button
//tap.cancelsTouchesInView = false
@jimbrayrcp
jimbrayrcp / Swipe Leading (Right Swipe).swift
Last active May 6, 2020 16:21
Swift 5: iOS: 13.1 - tableView Swipe Right Delete (or any function you want to add) Uses system images
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
// *** add object To be deleted ***
// object.delete
success(true)
})
action.image = UIImage(systemName: "trash.fill")
action.backgroundColor = .green
return UISwipeActionsConfiguration(actions: [action])
}
@jimbrayrcp
jimbrayrcp / Refresh UITableViewController.swift
Last active May 6, 2020 16:05
pull to refresh UITableVIewController Swift 5: iOS: 13.1
// -------------------------------------------
// Settings: Select the table view controller
// open the attributes inspector, and enable
// refreshing
// Add title color and center
// ****************************
// ADD TO VIEW DID LOAD
@jimbrayrcp
jimbrayrcp / Alert .actionSheet.swift
Created May 6, 2020 16:04
Swift 5: iOS: 13.1 Insert into any method for an action sheet alert type
let alertTitle = "Test"
let alertMessage = "Test Message"
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { action in
// Add Actions to this closure
print("Test Response")
}))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(alert, animated: true)