Skip to content

Instantly share code, notes, and snippets.

@shaundon
shaundon / WorkoutSplit.swift
Created February 21, 2021 17:34
Convert an array of HKQuantitySample into splits.
import Foundation
import HealthKit
struct WorkoutSplit: Hashable {
let label: String
let distance: HKQuantity
let duration: TimeInterval
}
extension WorkoutSplit {
@shial4
shial4 / DynamicList.swift
Last active June 7, 2024 09:25
SwiftUI Dynamic Horizontal or vertical List - loads only visible elements. Efficiency for large collections. Dynamic item size.
import SwiftUI
import Foundation
import PlaygroundSupport
public enum Orientation {
case horizontal
case vertical
}
public struct StackView<Content: View>: View {
@Wilsonilo
Wilsonilo / HstackDragDrop.swift
Last active November 2, 2022 01:14
Drag and Drop SwiftUI with ScrollView and HStack
//: HSTack /Scroll View With Drag and Drop
// By Wilson Munoz / @yosoywil
// Inspiration 1: https://gist.github.com/tarasis/f9bac6d98de5433f1ddbadaef02f9a29
// Inspiration 2: https://swiftui-lab.com/drag-drop-with-swiftui/
// Really dirty but functional, need to stress test with several items in the ScrollView/HStack and check memory.
import SwiftUI
import PlaygroundSupport
import Combine
@robherley
robherley / InterfaceController.swift
Created April 29, 2019 05:33
Health Kit Example - Updated for watchOS 5
//
// InterfaceController.swift
// AppleWatchExample WatchKit Extension
//
// Created by Robert Herley on 4/28/19.
// Copyright © 2019 Robert Herley. All rights reserved.
//
// Adapted From: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/speedysloth_creating_a_workout

UIButton + UILongPressGestureRecognizer

swift4

  • 通常のボタンタップとロングプレスを判定する
import UIKit

class ViewController: UIViewController {
@juzooda
juzooda / structToDic.playground
Created March 9, 2017 14:40
Simple Protocol to convert swift structs to dictionaries
import UIKit
struct Person: DictionaryConvertor {
let name: String
let job: [Job]?
let errors: [String]?
}
struct Job: DictionaryConvertor {
let title: String
@phatblat
phatblat / AppDelegate.swift
Last active May 4, 2024 12:34
Example of creating HKObserverQuery and enabling background delivery for multiple HKObjectType
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
let healthKitManager = HealthKitManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if onboardingComplete {
healthKitManager.requestAccessWithCompletion() { success, error in
if success { print("HealthKit access granted") }
else { print("Error requesting access to HealthKit: \(error)") }
}
@adamawolf
adamawolf / Apple_mobile_device_types.txt
Last active June 14, 2024 06:59
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
arm64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S