Skip to content

Instantly share code, notes, and snippets.

View PetreVane's full-sized avatar
🍃

Petre Vane PetreVane

🍃
View GitHub Profile
1- From Xcode menu open: Product > Scheme > Edit Scheme
2- On your Environment Variables set OS_ACTIVITY_MODE = disable
enum MagicError: Error {
case spellFailure
}
func castSpell(_spell: String) -> Result<String, MagicError> {
switch _spell {
case "flowers":
return .success("Flowers falling from sky")
case "stars":
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)
@PetreVane
PetreVane / DataManager.swift
Last active September 29, 2019 12:18
This snipped shows a well structured example of a Networking Class, used in makeing request to a Weather API server
import Foundation
enum DataManagerError: Error {
case Unknown
case FailedRequest
case InvalidResponse
}
// Stored & computed properties example
struct Person {
// strored properties
var firstName: String
var lastName: String
// computed property
var fullName: String {
class ImageFetcher: Operation {
var photo: PhotoRecord
init(photo: PhotoRecord) {
self.photo = photo
}
override func main() {
@PetreVane
PetreVane / TaskManager.swift
Created February 27, 2019 17:13 — forked from saoudrizwan/TaskManager.swift
Handle multiple network requests with the same URL efficiently with a shared task manager
import Foundation
class TaskManager {
static let shared = TaskManager()
let session = URLSession(configuration: .default)
typealias completionHandler = (Data?, URLResponse?, Error?) -> Void
var tasks = [URL: [completionHandler]]()