Skip to content

Instantly share code, notes, and snippets.

View Myrrel's full-sized avatar

Martín Urciuoli Myrrel

View GitHub Profile
@Myrrel
Myrrel / SceneDelegate.swift
Created March 15, 2024 13:43
SceneDelegate-SwiftUI
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
@Myrrel
Myrrel / Coordinator.swift
Last active March 11, 2024 20:16
UIKit + Coordinator
import Foundation
import UIKit
protocol Coordinator {
var viewController: UIViewController? {get}
var navigationController: UINavigationController? {get}
func start()
}
@Myrrel
Myrrel / TableviewDataSource.swift
Created March 10, 2024 18:00
iOS 14 — Modern Cell Configuration
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let item = items[indexPath.row]
var content = cell.defaultContentConfiguration()
content.image = UIImage(systemName: "star")
content.text = "Hello!"
cell.contentConfiguration = content
@Myrrel
Myrrel / fetchURLData.swift
Created March 8, 2024 13:55
fetchURLData with Generics
func fetchURLData<T: Decodable>(urlString: String, decodingType: T.Type) async throws -> T {
guard let url = URL(string: urlString) else {
throw URLError(.badURL)
}
let session = URLSession.shared
let (data, response) = try await session.data(from: url)
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
@Myrrel
Myrrel / ApiService.swift
Last active March 10, 2024 21:56
Endpoints with enum
import Foundation
// let charactersURL = ApiService.character.url
//output: url = https://rickandmortyapi.com/api/character
// let url = ApiService.characterPage(19).url
// output: url = https://rickandmortyapi.com/api/character/?page=19
enum ApiService {
@Myrrel
Myrrel / GridLayout-Example.swift
Last active November 13, 2023 16:55
Uso de gridlayout
//
// ContentView.swift
// cartographic-assistant
//
// Created by Harlock on 11/11/2023.
//
import SwiftUI
struct ContentView: View {
@Myrrel
Myrrel / Grand_Central_Dispatch.swift
Created October 18, 2023 03:03
Grand Central Dispatch examples
// # Serial queue
// Creating a custom serial queue with a specific label
let customQueue = DispatchQueue(label: "com.example.myqueue")
// Adding a task to the custom queue
customQueue.sync {
// Perform some work here
}
// # Concurrent queue
@Myrrel
Myrrel / UIColor-random.swift
Last active November 13, 2023 16:57
UIColor random extension
import UIKit
extension CGFloat {
static func random() -> CGFloat {
return CGFloat(arc4random()) / CGFloat(UInt32.max)
}
}
extension UIColor {
static func random() -> UIColor {
@Myrrel
Myrrel / SceneDelegate.swift
Last active April 16, 2025 21:29
Removing Storyboard From App [Xcode 14, Swift 5]
// 1. Delete the Main.storyboard file from the project. Click Move to Trash.
// 2. Remove Storyboard Name from File info.plist
// 3. Go to Application Target -> Build Settings -> Find the line: UIKit Main Storyboard File Base Name and remove the name of the storyboard.
// 4. In order to programmatically set the root controller of our application:
// Go to SceneDelegate file and in the func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) method add the following code:
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
@Myrrel
Myrrel / ecmascript 6, 7, 8, y 9
Last active November 22, 2020 21:18
ecmascript
// es6 ---- junio 2015
/**
* -----------------------------------------------------------Default Params
*/
function newFunction(name, age, country) {
var name = name || 'Oscar';
var age = age || 32;
var country = country || 'MX';
console.log(name, age, country);
}