Skip to content

Instantly share code, notes, and snippets.

View MKLocalSearchExample.swift
import SwiftUI
import MapKit
struct SearchTest: View {
@StateObject var infoService = LocationSearchService()
let center = CLLocationCoordinate2D(latitude: 34.0536909, longitude: -118.242766)
let radius = 100.0
var body: some View {
List(infoService.locationItems, id:\.self) { item in
@carlynorama
carlynorama / LocationPickerView.swift
Created Aug 10, 2022
Working on Setting Location
View LocationPickerView.swift
import SwiftUI
import CoreLocationUI
struct LocationPickerView: View {
@StateObject var locationManager = LocationManager()
@State private var locationName:String = ""
View chartExemple.Swift
//
// ChartTests.swift
// DataViewer
//
// Created by Labtanza on 8/3/22.
//
import SwiftUI
import Charts
@carlynorama
carlynorama / EnumPicker
Created Aug 3, 2022
Generates a picker when passed an Emum that conforms to PickerSuppiliable protocol
View EnumPicker
//
// EnumPicker.swift
// DataViewer
//
// Created by Carlyn Maw on 8/1/22.
//
import SwiftUI
@carlynorama
carlynorama / linear_solver.swift
Created Jul 30, 2022
linear equation solver from array of "DataPoints" a protocol that expects (x:Number, y:Number) tuple
View linear_solver.swift
//https://developer.apple.com/documentation/accelerate/working_with_matrices
// e.g. https://www.youtube.com/watch?v=wBxUa9tHkkE&list=PLMiyQ6EW11_lJT2YKm7kz_Uaa7M0LbBkP
typealias Number = Double
static func solveLinearPair(cx1:Number, cy1:Number, s1:Number, cx2:Number, cy2:Number, s2:Number) -> SIMD2<Number> {
let a = simd_double2x2(rows: [
simd_double2(cx1, cy1),
simd_double2(cx2, cy2)
])
@carlynorama
carlynorama / ScaledValue.swift
Last active Jul 25, 2022
Enum and function to swap different scaling styles.
View ScaledValue.swift
enum ScaleStyle {
case square
case squareRt
case beaufortScale
case log
case invlog
case linear
case inverted
case invertedSquare
}
@carlynorama
carlynorama / TaperSlider.swift
Last active Jul 23, 2022
A slider with a nonlinear taper, customizable. Most current version: https://github.com/carlynorama/TaperSlider
View TaperSlider.swift
//MOST RECENT VERSION: https://github.com/carlynorama/TaperSlider
//
// CustomTaperSlider.swift
//
//
// Created by Carlyn Maw on 7/15/22.
// License MIT
@carlynorama
carlynorama / CollapsableView.swift
Last active Jul 16, 2022
A container that collapses.
View CollapsableView.swift
//Based off of https://rensbr.eu/blog/swiftui-escaping-closures/
struct CollapsableView<Content: View>: View {
let content: Content
@Binding var isVisible:Bool
init(value:Binding<Bool>, @ViewBuilder content: () -> Content) {
self.content = content()
self._isVisible = value
}
@carlynorama
carlynorama / Compass.swift
Created Jul 1, 2022
potential extension to WeatherKit.Wind.CompassDirection testable as a playground
View Compass.swift
import Foundation
import SwiftUI
//TEST
print("----")
print("North")
print(Compass(degrees: 0).rawValue)
print(Compass(degrees: 5).rawValue)
print(Compass(degrees: 360-5).rawValue)
print("----")
View WindScale.swift
//
// WindDescriptions.swift
// Wind
//
// Created by Carlyn Maw on 6/23/22.
//
// Combination of Beaufort Wind Scale and Saffir-Simpson Hurricane Wind Scale
// windVelocity = 0.836 pow(B,3/2) m/s
import Foundation