This file contains hidden or 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
| // 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 |
This file contains hidden or 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. 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 |
This file contains hidden or 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. FocusState | |
| @FocusState private var isFocused: Bool | |
| // 2. Focused modifier | |
| TextField(". . . ", text: $item) | |
| .textFieldStyle(.plain) | |
| .padding(12) | |
| .background(.tertiary) | |
| .cornerRadius(12) | |
| .font(.title.weight(.light)) |
This file contains hidden or 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. Create Model | |
| import SwiftData | |
| @Model | |
| class Wish { | |
| var title: String | |
| init(title: String) { | |
| self.title = title |
This file contains hidden or 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 CustomListRow: View { | |
| @State var title: String | |
| @State var icon: String | |
| @State var content: String? = nil | |
| @State var tintColor: Color | |
| @State var link: String? = nil | |
| @State var linkDestination: String? = nil | |
| var body: some View { | |
| LabeledContent { |
This file contains hidden or 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 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 { |
This file contains hidden or 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 CustomCircleView: View { | |
| @State private var isAnimnateGradient = false | |
| var body: some View { | |
| ZStack { | |
| Circle() | |
| .fill( | |
| LinearGradient( | |
| colors: [ | |
| .colorIndigoMedium, |
This file contains hidden or 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
| // Simple | |
| Link("Go to Apple", destination: URL(string: "https://apple.com")!) | |
| .font(.largeTitle) | |
| // Custom | |
| Link(destination: URL(string: "https://apple.com")!) { | |
| HStack(spacing: 16) { | |
| Image(systemName: "apple.logo") | |
| Text("Apple Store") | |
| } |
This file contains hidden or 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
| @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]() |
NewerOlder