This file contains hidden or 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
| if FileManager.default.fileExists(atPath: fileURL.path) { | |
| do { | |
| let data = try Data(contentsOf: fileURL) | |
| /// Sweetie, this is the data you need to upload as the multipart form data | |
| /// via URLSession or Alamofire, Moya, whatever Network Library you're using! 🍻 | |
| } catch { | |
| print(error.localizedDescription) | |
| } | |
| } |
This file contains hidden or 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 MyViewController: UIDocumentMenuDelegate, UIDocumentPickerDelegate { | |
| func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { | |
| /// Handle your document | |
| } | |
| func documentMenu(_ documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) { | |
| documentPicker.delegate = self | |
| documentPicker.modalPresentationStyle = .overCurrentContext | |
| present(documentPicker, animated: true, completion: nil) | |
| } | |
| func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { |
This file contains hidden or 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 UIKit | |
| class ViewController: UIViewController { | |
| /// Creating UIDocumentInteractionController instance. | |
| let documentInteractionController = UIDocumentInteractionController() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| /// Setting UIDocumentInteractionController delegate. |
This file contains hidden or 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 UIView { | |
| /// Produce fade in animation | |
| func fadeIn(_ duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) { | |
| UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: { | |
| self.alpha = 1.0 | |
| }, completion: completion) | |
| } | |
| /// Produce fadeout animation |
This file contains hidden or 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 UIView { | |
| /// Sets border to the UIView | |
| func setViewBorder(withWidth width: CGFloat = 1.0, color: UIColor) { | |
| self.layer.borderWidth = width | |
| self.layer.borderColor = color.cgColor | |
| } | |
| } |
This file contains hidden or 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 UIView { | |
| /// Produce vertical shake animation | |
| func shakeVertically(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) { | |
| let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.y") | |
| animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) | |
| animation.repeatCount = count | |
| animation.duration = (duration)/TimeInterval(animation.repeatCount) | |
| animation.autoreverses = true |
This file contains hidden or 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 UIView { | |
| /// Sets rounded corners to the UIView | |
| func roundedCorners(radius: CGFloat? = nil) { | |
| if let radius = radius { | |
| layer.cornerRadius = radius | |
| } else { | |
| layer.cornerRadius = frame.size.height / 2 | |
| } | |
| clipsToBounds = true |
This file contains hidden or 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 UIView { | |
| /// Produce horizontal shake animation | |
| func shakeHorizontally(withCount count: Float = 4, duration: TimeInterval = 0.3, translation: Float = -10) { | |
| let animation: CABasicAnimation = CABasicAnimation(keyPath: "transform.translation.x") | |
| animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) | |
| animation.repeatCount = count | |
| animation.duration = (duration)/TimeInterval(animation.repeatCount) | |
| animation.autoreverses = true |
This file contains hidden or 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 setScaledCustomFont() { | |
| myLabel.font = getScaledFont(forFont: "Cambria-Bold", textStyle: .title1) | |
| myLabel.adjustsFontForContentSizeCategory = true | |
| } |
This file contains hidden or 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
| /// Get the Scaled version of your UIFont. | |
| /// | |
| /// - Parameters: | |
| /// - name: Name of the UIFont whose scaled version you wish to obtain. | |
| /// - textStyle: The text style for your font, i.e Body, Title etc... | |
| /// - Returns: The scaled UIFont version with the given textStyle | |
| func getScaledFont(forFont name: String, textStyle: UIFontTextStyle) -> UIFont { | |
| /// Uncomment the code below to check all the available fonts and have them printed in the console to double check the font name with existing fonts 😉 | |
NewerOlder