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
class ImageFetcher: Operation { | |
var photo: PhotoRecord | |
init(photo: PhotoRecord) { | |
self.photo = photo | |
} | |
override func main() { |
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
// Stored & computed properties example | |
struct Person { | |
// strored properties | |
var firstName: String | |
var lastName: String | |
// computed property | |
var fullName: String { |
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 | |
enum DataManagerError: Error { | |
case Unknown | |
case FailedRequest | |
case InvalidResponse | |
} |
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 Queue<Element> { | |
private var elements: [Element] = [] | |
var description: String { | |
return "Your queue has \(elements.count) items: \(elements)" | |
} | |
mutating func enqueue(newElement: Element) { | |
elements.append(newElement) |
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
enum MagicError: Error { | |
case spellFailure | |
} | |
func castSpell(_spell: String) -> Result<String, MagicError> { | |
switch _spell { | |
case "flowers": | |
return .success("Flowers falling from sky") | |
case "stars": |
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
1- From Xcode menu open: Product > Scheme > Edit Scheme | |
2- On your Environment Variables set OS_ACTIVITY_MODE = disable | |
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 fetchImageWithFileManager(image: String) -> UIImage? { | |
if let pathUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] { | |
let dirURL = pathUrl.appendingPathComponent(image) | |
do { | |
let imageData = try Data(contentsOf: dirURL) | |
return UIImage(data: imageData) | |
} catch { | |
print("Failed loading image") |
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 ErrorManager { | |
static func showError(message: String, on viewController: UIViewController?, dismissAction: ((UIAlertAction) -> Void)? = nil) { | |
weak var currentViewController = viewController | |
DispatchQueue.main.async { | |
let alertController = UIAlertController(title: "Error", message: message, preferredStyle: .alert) | |
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: dismissAction)) |
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
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
if segue.identifier == "showDetailedImage" { | |
guard let indexPath = tableView.indexPathForSelectedRow, | |
let destinationVC = segue.destination as? DetailsVC else {return} | |
let imageToBePassed = UIImage(named: testImages[indexPath.row]) |
OlderNewer