View MyViewController.swift
This file contains 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 SafariServices | |
func openURL(from urlString: String) { | |
guard let url = URL(string: urlString) else { return } | |
let svc = SFSafariViewController(url: url) | |
self.present(svc, animated: true, completion: nil) | |
} |
View MyViewController.swift
This file contains 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
func share(_ text: String) { | |
let activityVC = UIActivityViewController(activityItems: [text], applicationActivities: nil) | |
activityVC.excludedActivityTypes = [UIActivity.ActivityType.airDrop, | |
UIActivity.ActivityType.addToReadingList] | |
self.present(activityVC, animated: true, completion: nil) | |
} |
View MyModel.swift
This file contains 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 timeString: String { | |
let formatter = DateComponentsFormatter() | |
formatter.allowedUnits = [.month, .day, .hour, .minute] | |
formatter.unitsStyle = .abbreviated | |
formatter.zeroFormattingBehavior = .dropAll | |
if let date = self.date, let interval = formatter.string(from: date, to: Date()) { | |
return "\(interval) ago" | |
} | |
return "unknown" |
View UIImageViewExtension.swift
This file contains 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 UIImageView { | |
//Use this function with the imageview | |
func loadImageUsingCacheWithUrlString(_ url: String?) { | |
guard let url = url else { | |
self.image = UIImage(named: "default") | |
return | |
} | |
let imageName = url.split(separator: "/").last! as NSString | |
let fileManager = FileManager.default |
View UIViewControllerExtension.swift
This file contains 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 UIViewController { | |
func displaySpinner(onView : UIView) -> UIView { | |
let spinnerView = UIView.init(frame: onView.bounds) | |
spinnerView.backgroundColor = UIColor.white //UIColor.black.withAlphaComponent(0.5) | |
let ai = UIActivityIndicatorView(style: .gray) | |
ai.startAnimating() | |
ai.center = spinnerView.center | |
DispatchQueue.main.async { | |
spinnerView.addSubview(ai) |
View UIViewControllerExtension.swift
This file contains 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 UIViewController { | |
func showError(_ message: String?) { | |
let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} |
View DataManager.swift
This file contains 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
// | |
// DataManager.swift | |
// | |
// Created by Marcos Santos on 8/30/18. | |
// Copyright © 2018 Marcos Santos 2018. All rights reserved. | |
// | |
import CoreData | |
public class DataManager { |
View NSManagedObjectExtension.swift
This file contains 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
// | |
// NSManagedObject.swift | |
// | |
// Created by Marcos Santos on 8/30/18. | |
// Copyright © 2018 Marcos Santos 2018. All rights reserved. | |
// | |
import Foundation | |
import CoreData |
View UIColorExtension.swift
This file contains 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 UIColor { | |
convenience init(red: Int, green: Int, blue: Int) { | |
assert(red >= 0 && red <= 255, "Invalid red component") | |
assert(green >= 0 && green <= 255, "Invalid green component") | |
assert(blue >= 0 && blue <= 255, "Invalid blue component") | |
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0) | |
} | |
convenience init(rgb: Int) { |
NewerOlder