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 UIKit | |
extension UIView { | |
// In order to create computed properties for extensions, we need a key to | |
// store and access the stored property | |
fileprivate struct AssociatedObjectKeys { | |
static var tapGestureRecognizer = "MediaViewerAssociatedObjectKey_mediaViewer" | |
} | |
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
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(upgradeAlertViewOtherUpgradesLongPressHandler)) | |
longPress.minimumPressDuration = 0 | |
var longPressGRStartPoint: CGPoint? | |
var didCancelLongPressGR = false | |
func viewTouched(sender: UILongPressGestureRecognizer) { | |
let currentPoint = sender.location(in: self.view) | |
switch sender.state { | |
case .began: |
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 AudioToolbox.AudioServices | |
// 'Peek' feedback (weak boom) | |
let peek = SystemSoundID(1519) | |
AudioServicesPlaySystemSound(peek) | |
// 'Pop' feedback (strong boom) | |
let pop = SystemSoundID(1520) | |
AudioServicesPlaySystemSound(pop) |
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
struct Post: Codable { | |
let user: Int | |
let body: String | |
enum CodingKeys: String, CodingKey { | |
case user = "userId" | |
case body | |
} | |
} |
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 Foundation | |
public class Storage { | |
fileprivate init() { } | |
enum Directory { | |
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud. | |
case documents | |
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
class LinkResponsiveTextView: UITextView { | |
override init(frame: CGRect, textContainer: NSTextContainer?) { | |
super.init(frame: frame, textContainer: textContainer) | |
self.delaysContentTouches = false | |
// required for tap to pass through on to superview & for links to work | |
self.isScrollEnabled = false | |
self.isEditable = false | |
self.isUserInteractionEnabled = true |
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 os.log | |
os_log("[%{public}@/%{public}@:%{public}@] This is an error message", log: OSLog(subsystem: "my.system", category: "Networking"), type: OSLogType.error, ("\(#file)" as NSString).lastPathComponent, "\(#function)", "\(#line)") | |
// Alternatively use a global helper method | |
enum LogCategory: String { | |
case `default` = "Default" | |
case networking = "Networking" | |
} |
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 Foundation | |
class TaskManager { | |
static let shared = TaskManager() | |
let session = URLSession(configuration: .default) | |
typealias completionHandler = (Data?, URLResponse?, Error?) -> Void | |
var tasks = [URL: [completionHandler]]() |
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
let sameUrl = URL(string: "https://i.redd.it/dj4bz294zqhz.png")! | |
TaskManager.shared.dataTask(with: sameUrl) { (data, response, error) in | |
// ... | |
} | |
TaskManager.shared.dataTask(with: sameUrl) { (data, response, error) in | |
// ... | |
} |
NewerOlder