Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Working From Home

Rody Davis rodydavis

:octocat:
Working From Home
View GitHub Profile
@rodydavis
rodydavis / UIColor.swift
Created Nov 7, 2017
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
rodydavis / UITableViewCell.swift
Last active Nov 7, 2017
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 {
region.center = location.coordinate
@rodydavis
rodydavis / MapKitView.swift
Last active Nov 7, 2017
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
rodydavis / UITableviewController.swift
Last active Nov 9, 2017
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
rodydavis / MapKitMinimal.swift
Last active Nov 9, 2017
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
rodydavis / UITextField.swift
Created Nov 15, 2017
Scroll the Background so that the text fields are always visible (Swift 4)
View UITextField.swift
/*
https://github.com/hackiftekhar/IQKeyboardManager
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.
View States.swift
//States
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() {
super.viewDidLoad()
openAddressbook(vc: ViewController())
}
@rodydavis
rodydavis / CoreDataOrderSave.swift
Created Jan 14, 2018
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
RefreshCoredata()
if fromIndexPath.row > to.row
{
for i in to.row..<fromIndexPath.row
{
songs[i].setValue(i+1, forKey: "orderPosition")
You can’t perform that action at this time.