Skip to content

Instantly share code, notes, and snippets.

rodydavis / UIColor.swift
Created November 7, 2017 15:29
Making new UIColors easier
View UIColor.swift
//Extension to make it easy for UIColor init
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
let newRed = CGFloat(red)/255
let newGreen = CGFloat(green)/255
let newBlue = CGFloat(blue)/255
self.init(red: newRed, green: newGreen, blue: newBlue, alpha: 1.0)
rodydavis / UITableViewCell.swift
Last active November 7, 2017 15:56
Table View Cell button actions and actions from image view
View UITableViewCell.swift
class DashboardCell: UITableViewCell {
// MARK: - Properties
static let reuseIdentifier = "DashboardCell"
// MARK: -
@IBOutlet weak var lblHeaderTitle: UILabel!
//@IBOutlet weak var imgContactDetails: UIImageView!
@IBOutlet weak var lblDetail1: UILabel!
View Swift 4 - Address form String.swift
func map(address: String, title: String, name: String) {
let location = address
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(location) { [weak self] placemarks, error in
if let placemark = placemarks?.first, let location = placemark.location {
let mark = MKPlacemark(placemark: placemark)
let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
if var region = self?.mapView.region { = location.coordinate
rodydavis / MapKitView.swift
Last active November 7, 2017 16:11
View Controller for Map Kit (Get location from string)
View MapKitView.swift
// ContactMapView.swift
import UIKit
import MapKit
import Contacts
import CoreLocation
var addressString = "" //Pass Address String from other View Controllers
rodydavis / UITableviewController.swift
Last active November 9, 2017 12:47
Call, Email and Delete Cell Actions (Left and Right Swipe)
View UITableviewController.swift
override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
let indexPathIndex = tableView.indexPathForSelectedRow
let indexPath = indexPathIndex?.row ?? 0
let callButton = UITableViewRowAction(style: .normal, title: "📞\n Call") { action, index in
print("call button tapped")
let number = data[indexPath].phone ?? ""
print("Number: " + number)
UIApplication.makeAPhoneCall(number: number.replacingOccurrences(of: "-", with: ""))
rodydavis / MapKitMinimal.swift
Last active November 9, 2017 12:49
Address From String Function
View MapKitMinimal.swift
import UIKit
import MapKit
class MapViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapView: MKMapView!
var restaurant: RestaurantMO!
override func viewDidLoad() {
rodydavis / UITextField.swift
Created November 15, 2017 15:13
Scroll the Background so that the text fields are always visible (Swift 4)
View UITextField.swift
Extremely easy to install Swift or Objective-C.
Here how it works:
IQKeyboardManager (Swift):- IQKeyboardManagerSwift is available through CocoaPods, to install it simply add the following line to your Podfile: (#236)
// pod 'IQKeyboardManagerSwift'
//In AppDelegate.swift, just import IQKeyboardManagerSwift framework and enable IQKeyboardManager.
rodydavis / States.swift
Created November 20, 2017 19:56
States Swift 4
View States.swift
let states = [ "AK","AL","AR","AS","AZ","CA","CO","CT","DC","DE","FL","GA","GU","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY"]
View Contacts.swift
import ContactsUI
import UIKit
class ViewController: UIViewController, CNContactPickerDelegate {
override func viewDidLoad() {
openAddressbook(vc: ViewController())
rodydavis / CoreDataOrderSave.swift
Created January 14, 2018 02:11
How to save core data order list after rearranging and support for CRUD operations
View CoreDataOrderSave.swift
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
if let appDel = (UIApplication.shared.delegate as? AppDelegate) {
let contxt = appDel.persistentContainer.viewContext
if fromIndexPath.row > to.row
for i in to.row..<fromIndexPath.row
songs[i].setValue(i+1, forKey: "orderPosition")