Skip to content

Instantly share code, notes, and snippets.

View manusalinas-mx's full-sized avatar
🏠
Working from home

Manu Salinas manusalinas-mx

🏠
Working from home
View GitHub Profile
// MARK: - Generic Method
// Método genérico para obtener datos
private func fetchData<T: Decodable>(from url: URL) async throws -> T {
let (data, _) = try await URLSession.shared.data(from: url)
let decodedData = try JSONDecoder().decode(T.self, from: data)
return decodedData
}
// Usage
// 1. Create Tip struct
import TipKit
struct ButtonTip: Tip {
var title: Text = Text("Essential Foods")
var message: Text? = Text("Add some everyday items to the shopping list.")
var image: Image? = Image(systemName: "info.circle")
}
// 2. Setup on View
// 1. FocusState
@FocusState private var isFocused: Bool
// 2. Focused modifier
TextField(". . . ", text: $item)
.textFieldStyle(.plain)
.padding(12)
.background(.tertiary)
.cornerRadius(12)
.font(.title.weight(.light))
@manusalinas-mx
manusalinas-mx / SwiftData: Basics.swift
Created January 14, 2025 15:54
Create and Delete
// 1. Create Model
import SwiftData
@Model
class Wish {
var title: String
init(title: String) {
self.title = title
import SwiftUI
struct GradientButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding(.vertical)
.padding(.horizontal, 30)
.background(
configuration.isPressed
?
struct MotionAnimationView: View {
// MARK: Properties
@State private var randomCircle: Int = Int.random(in: 6 ... 12)
@State private var isAnimated: Bool = false
// MARK: Functions
// 1. Random Coordinate
func randomCoordinate() -> CGFloat {
struct CustomCircleView: View {
@State private var isAnimnateGradient = false
var body: some View {
ZStack {
Circle()
.fill(
LinearGradient(
colors: [
.colorIndigoMedium,
@Published private(set) var users: [User] = []
func load() async {
let userIDs = [1, 2, 3, 4, 5, 6, 7]
users = await = withTaskGroup(of: User.self, returning: [User].self) { group in
for id in userIDs {
group.addTask { await self.userService.fetchUserInfo(userID: id) }
}
var users = [User]()