Skip to content

Instantly share code, notes, and snippets.

View notoroid's full-sized avatar

Kaname Noto notoroid

View GitHub Profile
@notoroid
notoroid / 01_sf-symbols-sample.swift
Last active December 30, 2020 05:25
SFSymbolsSample for SwiftUI
import SwiftUI
import DeviceGuru
enum DeviceStyleIcon: String {
case phoneHome = "phh" // iPhone and iPod touch devices with homebutton
case phone = "ph" // iPhone
case padHome = "pah" // iPad witn homebutton
case pad = "pa" // iPad
case none = "n" // none (AppleWatch, appleTV, mac)
}
@notoroid
notoroid / 02_ArchiveBench.swift
Created January 3, 2021 06:39
Apple M1 chip archive benchmark for macOS app
import SwiftUI
import Combine
import AppleArchive
import System
enum ArchiveBenchResult {
case failureError(error: Error)
case notExistsSourceFile
case notOpenReadFileStream
case notOpenWriteFileStream
@notoroid
notoroid / 03_motion-tabbar.swift
Last active January 14, 2021 05:43
Building a Beautiful Animated Motion Tab Bar Widget With SwiftUI.
import SwiftUI
struct TopFrameView: Shape {
func path(in rect: CGRect) -> Path {
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 53.22, y: 4.36))
for (to, controlPoint1, controlPoint2) in [(CGPoint(x: 60.83, y: 13.06), CGPoint(x: 57.76, y: 7.77), CGPoint(x: 60.14, y: 11.68)), (CGPoint(x: 68.43, y: 22.84), CGPoint(x: 63, y: 17.4), CGPoint(x: 65.05, y: 20.96)), (CGPoint(x: 75.16, y: 23.98), CGPoint(x: 70.49, y: 23.98), CGPoint(x: 75.16, y: 23.98))] {
bezierPath.addCurve(to: to, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
}
bezierPath.addLine(to: CGPoint(x: 0.84, y: 23.98))
import SwiftUI
struct TopFrameView: Shape {
func path(in rect: CGRect) -> Path {
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 9.16, y: 0.04))
let curvePoints = [(CGPoint(x: 22.13, y: 1.8), CGPoint(x: 13.75, y: 0.17), CGPoint(x: 18.98, y: 0.6)), (CGPoint(x: 36.89, y: 10.14), CGPoint(x: 28.69, y: 4.3), CGPoint(x: 31.15, y: 4.93)), (CGPoint(x: 46.73, y: 22.65), CGPoint(x: 42.63, y: 15.35), CGPoint(x: 44.27, y: 18.48)), (CGPoint(x: 58.2, y: 34.32), CGPoint(x: 49.19, y: 26.81), CGPoint(x: 52.47, y: 30.78)), (CGPoint(x: 70.5, y: 37.65), CGPoint(x: 63.94, y: 37.86), CGPoint(x: 70.5, y: 37.65)), (CGPoint(x: 82.8, y: 34.32), CGPoint(x: 70.5, y: 37.65), CGPoint(x: 77.06, y: 37.86)), (CGPoint(x: 94.27, y: 22.65), CGPoint(x: 88.53, y: 30.78), CGPoint(x: 91.81, y: 26.81)), (CGPoint(x: 104.11, y: 10.14), CGPoint(x: 96.73, y: 18.48), CGPoint(x: 98.37, y: 15.35)), (CGPoint(x: 118.87, y: 1.8), CGPoint(x: 109.85, y: 4.93), CGPoint(x: 112.31, y: 4.3)), (CGPoint(x: 140.79, y: 0.12)
@notoroid
notoroid / 05_mechanical-arm.swift
Created February 14, 2021 02:54
Sample of using SwifUI's rotationEffect modifier.
import SwiftUI
enum MechanicalArm {
static let colors: [Color] = [Color(UIColor(red: 0.349, green: 0.671, blue: 0.914, alpha: 1.000)) /*.red, .green, .yellow, .blue, .yellow*/]
static let manipulatorJointEdge = CGFloat(16.5); static let manipulatorRootEdge = CGFloat(37.5)
static let manipulatorWidth = CGFloat(9); static let manipulatorFirstLength = CGFloat(60); static let manipulatorOtherLength = CGFloat(37.5)
static let armLength = CGFloat(105); static let armWidth = CGFloat(37.5); static let armJointEdge = CGFloat(16.5)
static let standWidth = CGFloat(75); static let standHeighth = CGFloat(60)
static let defaultArmAngle = Double(0); static let defaultWristAngle = Double(-45); static let defaultFingerAngle = Double(40)
}
struct ContentView: View {
@AppStorage(wrappedValue: false, "enabled_preference") var enabled_preference
var body: some View {
NavigationView {
Text("The toolbar is displayed in conjunction with the switch On/Off in the Settings application - Third Party Application Settings - Sample Application Settings.\n\nNote: The AppStorage value will revert to its initial value after each app transfer after the build, so build carefully.")
.padding()
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
if enabled_preference {
Spacer()
import SwiftUI
enum TextFieldTypes {
case defaultStyle
case customStyle
}
struct ContentView: View {
@State var myfield = ""
@ScaledMetric(relativeTo: .body) var imageSize = CGFloat(2)
import SwiftUI
import UIKit
// Debug.xcconfig
// OTHER_SWIFT_FLAGS = $(inherited) "-D" "DEBUG"
// DebugStage.xcconfig
// OTHER_SWIFT_FLAGS = $(inherited) "-D" "DEBUG" "-D" "STAGE"
// Release.xcconfig
import SwiftUI
//
// ContentView.swift
// ListSampleUsingCaseIterable
//
// Created by 能登 要 on 2021/04/14.
//
import SwiftUI
@notoroid
notoroid / 10_watchos-interval-background-task.swift
Last active December 22, 2021 10:45
watchOS8.0 interval background task sample.
import SwiftUI
struct RandomFox: Equatable, Codable { let image: String; let link: String }
class ExtensionDelegate: NSObject, ObservableObject, WKExtensionDelegate {
var foregroundDataTask: URLSessionDataTask?; var backgroundDataTask: URLSessionDataTask?
var timer: Timer?
let url = URL(string: "https://randomfox.ca/floof/")!
@Published var randomFox: RandomFox? = nil
// utilities
func taskRandomFox(completionHandler: @escaping (Error?) -> Void) -> URLSessionDataTask { // DataTask create function