Skip to content

Instantly share code, notes, and snippets.

View CrystalKnightCodes's full-sized avatar
👩‍💻

Crystal Knight CrystalKnightCodes

👩‍💻
View GitHub Profile
@CrystalKnightCodes
CrystalKnightCodes / Models.swift
Created March 30, 2021 15:09
TabView Tutorial Models
import MapKit // So we can store coordinates.
/// A single location.
struct Place: Identifiable, Equatable, Hashable {
let id = UUID() // Required to conform to Identifiable
var name: String
var latitude: Double
var longitude: Double
var coordinate: CLLocationCoordinate2D {
CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
@CrystalKnightCodes
CrystalKnightCodes / MockData.swift
Last active January 12, 2022 22:14
TabView Tutorial Mock Data
// MARK: - Florida
// Locations
var mysticalKingdom = Place(
name: "Mystical Kingdom",
latitude: 28.4177,
longitude: -81.5812)
var aroundTheWorld = Place(
name: "Around the World",
latitude: 28.3747,
@CrystalKnightCodes
CrystalKnightCodes / ContentView.swift
Created March 30, 2021 15:17
TabView Tutorial Content View
import SwiftUI
struct ContentView: View {
// MARK: - Properties
@State var results = [Vacation]()
@State var selection = 0
// MARK: - View
var body: some View {
VStack(alignment: .center) {
SearchBarView()
@CrystalKnightCodes
CrystalKnightCodes / SearchBarView.swift
Last active March 30, 2021 15:22
TabView Tutorial Search Bar View Initial Setup
import SwiftUI
struct SearchBarView: View {
// MARK: - Properties
@State private var text: String = ""
@Binding var results: [Vacation]
// MARK: - View
var body: some View {
VStack(alignment: .leading) {
@CrystalKnightCodes
CrystalKnightCodes / SearchBarView.swift
Created March 30, 2021 15:25
TabView Tutorial Search Bar Method
struct SearchBarView: View {
//...
// MARK: - Methods
func findGroup() {
results = vacations.all { vacation -> Bool in
// First check to see if the text is in the vacation name
if vacation.name.localizedCaseInsensitiveContains(text) {
return true
// If it isn't in the vacation name, search through each place.
} else {
@CrystalKnightCodes
CrystalKnightCodes / SearchMapView.swift
Last active April 8, 2021 14:49
TabView Tutorial Search Map View
import SwiftUI
import MapKit
struct SearchMapView: View {
// MARK: - Properties
@ObservedObject private var regionModel = RegionModel(
region: MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 39.8333,
longitude: -98.5833
@CrystalKnightCodes
CrystalKnightCodes / ResultCardView.swift
Created March 30, 2021 15:30
Tabview Tutorial Result Card View
import SwiftUI
struct ResultCardView: View {
// MARK: - Properties
var vacation: Vacation
// MARK: - View
var body: some View {
HStack(alignment: .top) {
Image(systemName: vacation.imageName)
@CrystalKnightCodes
CrystalKnightCodes / SearchResultsView.swift
Created March 30, 2021 15:32
TabView Tutorial Search Results View Initial Setup
import SwiftUI
struct SearchResultsView: View {
// MARK: - Properties
@Binding var results: [Vacation]
@Binding var selection: Int
// MARK: - View
var body: some View {
VStack(alignment: .leading) {
@CrystalKnightCodes
CrystalKnightCodes / RegionModel.swift
Last active April 8, 2021 14:40
Tabview Tutorial Region Model
class RegionModel: ObservableObject
{
@Published var region: MKCoordinateRegion
init(region: MKCoordinateRegion)
{
self.region = region
}
}
import SwiftUI
import ComposableArchitecture
struct HotlistSelector: View
{
let store: Store<HotlistManagementState, HotlistManagementAction>
var body: some View {
WithViewStore(store) { (viewStore: ViewStore<HotlistManagementState, HotlistManagementAction>) in