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
struct Message { | |
let id: String | |
let body: String | |
} | |
let messages = [Message(id: "1", body: "..."), Message(id: "2", body: "..."), Message(id: "3", body: "...")] | |
// or retrieve your messages from Disk... | |
let messages = try! Disk.retrieve("messages.json", from: .documents, as: [Message].self) | |
var messagesWithoutIdOf2 = [Message]() |
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 logs = ["Error", "Created", "Crashed"] | |
logs.forEach { print($0) } | |
// prints "Error" | |
// prints "Created" | |
// prints "Crashed" |
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 | |
// ... | |
} |
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
import UIKit | |
var feedbackGenerator : UISelectionFeedbackGenerator? = nil | |
@IBAction func gestureHandler(_ sender: UIPanGestureRecognizer) { | |
switch sender.state { | |
case .began: | |
// Instantiate a new generator | |
feedbackGenerator = UISelectionFeedbackGenerator() | |
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 | |
class ResponsiveView: UIView { | |
override var canBecomeFirstResponder: Bool { | |
return true | |
} | |
} |
NewerOlder