Skip to content

Instantly share code, notes, and snippets.

View MarkVillacampa's full-sized avatar
:octocat:
just setting up my gthb

Mark Villacampa MarkVillacampa

:octocat:
just setting up my gthb
View GitHub Profile
@MoussaHellal
MoussaHellal / RingAnimation.swift
Created January 23, 2024 11:51
RingAnimation
//
// ContentView.swift
// Animating Cirlce
//
// Created by Moussa on 23/1/2024.
//
import SwiftUI
@davidsteppenbeck
davidsteppenbeck / iOS.swift
Created May 15, 2023 12:42
Typealias + extension examples for multiplatform development in Swift.
import SwiftUI
/*
Put these in a file that is compiled for iOS only.
Note that these are just a few examples of things that worked well in my project.
They may or may not be useful to you, but they give an idea of how typealias + extensions
could be used to keep your code tidy.
*/
@davidsteppenbeck
davidsteppenbeck / MultiplatformLabel.swift
Created May 15, 2023 12:13
A platform specific label for SwiftUI.
import SwiftUI
/// Provides a text label appropriate for the current platform.
///
/// Specifically, this provides a `Label` with the specified system image on iOS and `Text` without an image on macOS.
struct MultiplatformLabel: View {
// MARK:- Properties
/// A title generated from a localized string.
@davidsteppenbeck
davidsteppenbeck / MultiplatformWidgetFamily.swift
Created May 15, 2023 11:57
A method for specifying multiplatform widget families in Swift.
import SwiftUI
import WidgetKit
@available(iOS 16.0, macOS 13.0, *)
public enum MultiplatformWidgetFamily: CaseIterable {
/// A small widget.
///
/// The small system widget can appear on the Home Screen or in the Today View in iOS and iPadOS, or in the Notification Center on macOS.
case systemSmall
@davidsteppenbeck
davidsteppenbeck / WidgetFamily+Utilities.swift
Created May 15, 2023 11:54
Methods for providing widget family specific values in Swift.
import SwiftUI
import WidgetKit
@available(iOS 14.0, macOS 11.0, *)
public extension WidgetFamily {
/// Returns the value for the current widget family.
///
/// If no value is provided for the current widget family, the method will return the `defaultValue`.
///
@davidsteppenbeck
davidsteppenbeck / ValueForDevice.swift
Created May 15, 2023 11:45
Global functions for providing device specific values in Swift.
import Foundation
/*
Put these global functions in a file that is compiled for all platforms.
*/
/// Returns the value for the current device from the values that are provided.
///
/// - Parameters:
/// - phoneValue: The value to use for iPhone.
@davidsteppenbeck
davidsteppenbeck / ValueForPlatform.swift
Last active December 25, 2023 22:27
A global function for providing multiplatform specific values in Swift.
import Foundation
/// Returns the value for the current platform from the values that are provided.
///
/// - Parameters:
/// - iOSValue: The value to use for the iOS platform.
/// - macOSValue: The value to use for the macOS platform.
func valueForPlatform<Value>(iOS iOSValue: @autoclosure () -> Value, macOS macOSValue: @autoclosure () -> Value) -> Value {
#if os(iOS)
iOSValue()
@hrules6872
hrules6872 / ComposeStore.kt
Last active April 2, 2023 17:03
Zustand 🐻 implementation for Kotlin :) https://github.com/pmndrs/zustand
/*
* Copyright (c) 2022. Héctor de Isidro - hrules6872
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@roostr
roostr / Watchdog.swift
Last active March 19, 2024 14:40
A watchdog timer for iOS to detect when the main run loop is stalled
//
// Watchdog.swift
//
// The MIT License (MIT)
// Copyright © 2023 Front Pocket Software LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
@krzyzanowskim
krzyzanowskim / PastelColor.swift
Last active February 10, 2024 10:27
Random pastel colors
struct ContentView: View {
@State var color: Color = .Pastel.random()
var body: some View {
Rectangle()
.foregroundColor(color)
.onTapGesture {
color = .Pastel.random()
}
}