Skip to content

Instantly share code, notes, and snippets.

// Original article here: https://www.fivestars.blog/code/section-title-index-swiftui.html
import SwiftUI
let database: [String: [String]] = [
"iPhone": [
"iPhone", "iPhone 3G", "iPhone 3GS", "iPhone 4", "iPhone 4S", "iPhone 5", "iPhone 5C", "iPhone 5S", "iPhone 6", "iPhone 6 Plus", "iPhone 6S", "iPhone 6S Plus", "iPhone SE", "iPhone 7", "iPhone 7 Plus", "iPhone 8", "iPhone 8 Plus", "iPhone X", "iPhone Xs", "iPhone Xs Max", "iPhone Xʀ", "iPhone 11", "iPhone 11 Pro", "iPhone 11 Pro Max", "iPhone SE 2"
],
"iPad": [
"iPad", "iPad 2", "iPad 3", "iPad 4", "iPad 5", "iPad 6", "iPad 7", "iPad Air", "iPad Air 2", "iPad Air 3", "iPad Mini", "iPad Mini 2", "iPad Mini 3", "iPad Mini 4", "iPad Mini 5", "iPad Pro 9.7-inch", "iPad Pro 10.5-inch", "iPad Pro 11-inch", "iPad Pro 11-inch 2", "iPad Pro 12.9-inch", "iPad Pro 12.9-inch 2", "iPad Pro 12.9-inch 3", "iPad Pro 12.9-inch 4"
@wb-towa
wb-towa / convert.swift
Created August 13, 2021 15:56 — forked from SatoTakeshiX/convert.swift
Take capture a view by SwiftUI
//
// ContentView.swift
// TryGeometryReader
//
// Created by satoutakeshi on 2019/12/07.
// Copyright © 2019 satoutakeshi. Licensed under MIT.
//
import SwiftUI
@wb-towa
wb-towa / SwiftUI Tagger.swift
Created November 29, 2021 21:57 — forked from mralexhay/SwiftUI Tagger.swift
A SwiftUI interface for adding tags
//
// TaggerView.swift
//
// Created by Alex Hay on 21/11/2020.
//
// Simple interface for adding tags to an array in SwiftUI
// Example video: https://imgur.com/gallery/CcA1IXp
// alignmentGuide code from Asperi @ https://stackoverflow.com/a/58876712/11685049
import SwiftUI
import UIKit
extension UITextField {
/// Add a trailing placeholder label that tracks the text as it changes
func addTrailingPlaceholder(_ placeholder: String) {
let label = UILabel()
label.text = placeholder
label.alpha = 0.3
label.isHidden = true
addSubview(label)
@wb-towa
wb-towa / healthkit-async-await-workouts.swift
Created January 28, 2022 09:26 — forked from tshortli/healthkit-async-await-workouts.swift
A Swift async function that gets the most recent workouts from HealthKit
func mostRecentWorkouts(for healthStore: HKHealthStore, limit: Int) async throws -> [HKWorkout] {
let query = HKSampleQueryDescriptor(
predicates: [.workout()],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
limit: limit
)
return try await query.result(for: healthStore)
}
import SwiftUI
struct ContentView: View {
@State var pictureExpanded = false
var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")
Button {
@wb-towa
wb-towa / playground.swift
Created May 26, 2022 09:46 — forked from BrandonShega/playground.swift
Table View Section Index List
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import PlaygroundSupport
let allStates = ["Alaska",
"Alabama",
"Arkansas",
"American Samoa",
@wb-towa
wb-towa / Setup.swift
Created May 26, 2022 09:47 — forked from DavidPiper94/Setup.swift
Example code for article about section index - Setup of UITableView
class ViewController: UIViewController {
// 1
@IBOutlet weak var tableView: UITableView!
// 2
let sectionTitles = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".map(String.init)
}
extension ViewController: UITableViewDataSource {
@wb-towa
wb-towa / FreeSpaceViewController.swift
Created October 8, 2022 10:23 — forked from kylehowells/FreeSpaceViewController.swift
UIViewController subclass to show both the Settings app displayed free space, and the real free space.
//
// FreeSpaceViewController.swift
// Free Space
//
// Created by Kyle Howells on 04/05/2022.
//
import UIKit
class FreeSpaceViewController: UIViewController {
@wb-towa
wb-towa / AttributedString.swift
Created March 19, 2023 17:32 — forked from chockenberry/AttributedString.swift
A playground that shows how to use Swift's AttributedString with Markdown
import UIKit
import Foundation
// NOTE: This playground shows how to use Swift's AttributedString with Markdown.
//
// This code was used to display Markdown content in the Tot iOS Widget <https://tot.rocks>
// MARK: - Helpful Links
// NOTE: The following links helped me figure this stuff out.