This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TobiType.swift | |
// | |
// https://twitter.com/dunkeeel/status/1587206501004939264?s=61&t=B4d_UGPw9A9ZN3A894q5yQ | |
import SwiftUI | |
struct TobiType: View { | |
struct SingleLetter: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Edut(r)ainMe - Day35 | |
// | |
// Created by mbr73 on 04.10.22. | |
// | |
import SwiftUI | |
struct Question { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------------------------------- | |
// 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================================== | |
// 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
let legs = 4 | |
} | |
class Dog: Animal { | |
func speak() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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 } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func f(_ array: [Int]? ) -> Int { | |
return array?.randomElement() ?? Int.random(in: 1...100) | |
} | |
f(nil) | |
f([Int]()) | |
f([-1,-2,-3]) | |
NewerOlder