100 Days of SwiftUI(DAY 29 (Project 5)

WordScrambleという新しいシングルビューアプリプロジェクト

Introducing List, your best friend

List {
    Text("Hello World")
    Text("Hello World")
    Text("Hello World")
}

List {
    ForEach(0..<5) {
        Text("Dynamic row \($0)")
    }
}

List {
    Text("Static row 1")
    Text("Static row 2")

    ForEach(0..<5) {
        Text("Dynamic row \($0)")
    }

    Text("Static row 3")
    Text("Static row 4")
}

List {
    Section(header: Text("Section 1")) {
        Text("Static row 1")
        Text("Static row 2")
    }

    Section(header: Text("Section 2")) {
        ForEach(0..<5) {
            Text("Dynamic row \($0)")
        }
    }

    Section(header: Text("Section 3")) {
        Text("Static row 3")
        Text("Static row 4")
    }
}

.listStyle(GroupedListStyle())

List(0..<5) {
    Text("Dynamic row \($0)")
}

struct ContentView: View {
    let people = ["Finn", "Leia", "Luke", "Rey"]
    var body: some View {
       List {
           ForEach(people, id: \.self) {
               Text($0)
           }
       }
    }
}

Loading resources from your app bundle
App Bundleからのリソースの読み込み


if let fileURL = Bundle.main.url(forResource: "some-file", withExtension: "txt") {
    // we found the file in our bundle!
}

if let fileContents = try? String(contentsOf: fileURL) {
    // we loaded the file into a string!
}

Working with strings
文字列の操作

let input = "a b c"
let letters = input.components(separatedBy: " ")


let input = """
            a
            b
            c
            """
let letters = input.components(separatedBy: "\n")


let letter = letters.randomElement()

let trimmed = letter?.trimmingCharacters(in: .whitespacesAndNewlines)


let word = "swift"
let checker = UITextChecker()


let range = NSRange(location: 0, length: word.utf16.count)


let misspelledRange = checker.rangeOfMisspelledWord(in: word, range: range, startingAt: 0, wrap: false, language: "en")


let allGood = misspelledRange.location == NSNotFound