Skip to content

Instantly share code, notes, and snippets.

@JZDesign
JZDesign / enum.playground
Last active February 20, 2020 12:35
Enum lesson starter for swift playground
import UIKit
import PlaygroundSupport
// MARK: - Setup
let view: UIView = {
let view = UIView(frame: .init(x: 0, y: 0, width: 300, height: 300))
view.backgroundColor = .white
return view
@JZDesign
JZDesign / enum.playground
Created February 20, 2020 12:57
Full Enum Playground from class
import UIKit
import PlaygroundSupport
// MARK: - Setup
let view: UIView = {
let view = UIView(frame: .init(x: 0, y: 0, width: 300, height: 300))
view.backgroundColor = .white
return view
import Foundation
class CounterTopDishwasher {
var dishes: [String] = []
var space = 10
var isClean = false
func run() {
if (!isClean) {
isClean = true
struct RatingStar: View {
var rating: CGFloat
var color: Color
var index: Int
var maskRatio: CGFloat {
let mask = rating - CGFloat(index)
@JZDesign
JZDesign / star.csv
Last active September 19, 2020 20:28
Star Index Mask Value After normailzation
0 3.6 1
1 2.6 1
2 1.6 1
3 0.6 0.6
4 0 0
public struct FiveStarView: View {
var rating: Decimal
var color: Color
var backgroundColor: Color
public init(
rating: Decimal,
color: Color = .red,
backgroundColor: Color = .gray
) {
private struct StarImage: View {
var body: some View {
Image(systemName: "star.fill")
.resizable()
.aspectRatio(contentMode: .fill)
}
}
struct ContentView: View {
@State var shouldShow = false
var body: some View {
Text("Press me!")
.font(.largeTitle)
.fontWeight(.semibold)
.foregroundColor(.orange)
.onTapGesture { shouldShow = true }
import SwiftUI
struct ShetlerView: View {
@ObservedObject var scheduler = Scheduler()
var body: some View {
List(0..<scheduler.reservableTimes.count) { index in
let time = scheduler.reservableTimes[index]
Text(time.time)
.foregroundColor(scheduler.selectedTimes.contains(time) ? .gray : .black)

Understanding Table Views and Index Paths

The UITableView relies on 2 different delegates to do it's job:

  1. UITableViewDataSource
  2. UITableViewDelegate

The data source tells the view what to display. The delegate tells the view how to respond to specific events like when a user taps on a cell.