Skip to content

Instantly share code, notes, and snippets.

@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 6 - Checkpoint 3.swift
Last active December 7, 2022 22:41
Wanted to make use of what we learned about switch statements and arrays and such in #100DaysOfSwiftUI. So here to come my 6 solutions for 'Checkpoint 3' ...
// Solution 1: Straightforward, I guess this is the standard way to tackle the task?!?
// Note: The order in which the conditions are checked is crucial - you see why?!?
for i in 1...100 {
if i.isMultiple(of: 3) && i.isMultiple(of: 5) {
print("FizzBuzz")
} else if i.isMultiple(of: 3) {
print("Fizz")
@nmbr73
nmbr73 / TobiType.swift
Last active November 2, 2022 00:04
A nice text effect implemented in SwiftUI by Tobias @Dunkeeel Dunkel.
//
// TobiType.swift
//
// https://twitter.com/dunkeeel/status/1587206501004939264?s=61&t=B4d_UGPw9A9ZN3A894q5yQ
import SwiftUI
struct TobiType: View {
struct SingleLetter: View {
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 35 - Edutainment App.swift
Created October 5, 2022 13:42
This is the 'Education' part only - it's a mess already and so I did not go down the 'Entertainment' route.
//
// ContentView.swift
// Edut(r)ainMe - Day35
//
// Created by mbr73 on 04.10.22.
//
import SwiftUI
struct Question {
@nmbr73
nmbr73 / 100DaysOfSwiftUI - Day 14 - Optionals.swift
Last active October 5, 2022 09:19
Accessing optionals ... or: What happens when you want to avoid `if (...!=NULL)` in your language 😜
// --------------------------------------------------------------------------
// Summary of the (as always) excelent content
// of https://www.hackingwithswift.com/100/swiftui/14
// by #HACKINGWITHSWIFT's Paul @twostraws Hudson.
// --------------------------------------------------------------------------
enum BadCaptain : Error {
case noGood
}
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 9 - Checkpoint 5.swift
Last active September 28, 2022 09:17
How I tried to tackle the ninth day challenge of #100DaysOfSwiftUI ... having a syntax issue with example C here.
let luckyNumbers = [7, 4, 38, 21, 16, 15, 12, 33, 31, 49]
print("--- A ---")
// First approach is with closures as parameters ... but how to do the "print one item per line"
// without a for loop?!? We don't know forEach yet, or do we?
for n in luckyNumbers
@nmbr73
nmbr73 / 100DaysOfSwiftUI - Day 9 - Checkpoint 5 - Whitespace.swift
Last active September 28, 2022 09:16
A basic syntax question I'm having just starting out with the Swift programming language ... I wished @twostraws would have added a video on whitespace for the #100DaysOfSwitUI 😜
// ==============================================================================================
// How can it be explained that Swift interprets whitespace and whitespace so differently?!?
// ----------------------------------------------------------------------------------------------
// Must be some "a line break makes a chain of commands a sequence and therefore a line
// break cannot be used in places where a semicolon would obviously not be allowed". But
// I don't see it and some explanation would be much appreciated!
// ==============================================================================================
let luckyNumbers = [7, 4, 38, 21, 16, 15, 12, 33, 31, 49]
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 11 - Checkpoint 6.swift
Last active September 28, 2022 09:13
My attempt to solve 'Checkpoint 6' of #100DaysOfSwiftUI (https://www.hackingwithswift.com/100/swiftui)
// Bear with me - sure, exceptions, custom initializers, observers, static methods,
// computed properties, etc. are really not all needed to solve the problem, but I
// wanted to try some of the things we learned so far and thereby the code got a bit
// bloated maybe.
struct NonSense: Error {
}
struct Car {
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 12 - Checkpoint 7.swift
Last active September 28, 2022 09:12
Day 12, Checkpoint 7 of #100DaysOfSwiftUI ... nothing special here, I think ... ?!?
class Animal {
let legs = 4
}
class Dog: Animal {
func speak() {
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 13 - Checkpoint 8.swift
Last active September 28, 2022 09:11
Day 13, Checkpoint 8 of #100DaysOfSwiftUI ... thanks @twostraws - I really enjoy the course so far!
/// Any kind of building on the estate market.
///
protocol Building {
/// Number of rooms the building has.
///
/// Note that the numebr of rooms can't change heavy construction work.
var rooms: Int { get }
@nmbr73
nmbr73 / 100DaysOfSwitfUI - Day 14 - Checkpoint 9.swift
Last active September 28, 2022 09:10
Day 14, Checkpoint 9 of #100DaysOfSwiftUI ... where @twostraws provided some excellent content again! #HACKINGWITHSWIFT https://www.hackingwithswift.com/quick-start/beginners/checkpoint-9
func f(_ array: [Int]? ) -> Int {
return array?.randomElement() ?? Int.random(in: 1...100)
}
f(nil)
f([Int]())
f([-1,-2,-3])