Questions tagged [swift-structs]

Use this tag for questions related to Swift structs, which allows you to create a structured data type, in Swift.

A allows you to create a structured data type which provides storage of data using properties and extending its functionality via methods.

as discussed here.

You are encouraged to use the along with .

69 questions
-1
votes
1 answer

Having trouble with "Return from initializer without initializing all stored properties" error

Having trouble resolving this error "Return from initializer without initializing all stored properties" Here is the code that prompted the error, import SwiftUI struct TaskEditView: View { @Environment(\.presentationMode) var presentationMode:…
-1
votes
1 answer

【SwiftUI】How to initialize an empty struct

I need some kind help in SwiftUI. I have a model below that takes in JSON data. When I want to initialize it as an empty array, it should be simple, just stating Answers, but how can I initialize it not as an array but an empty single data…
Hiro
  • 155
  • 1
  • 10
-1
votes
1 answer

Apple's SwiftUI Tutorial: I'm Stumped

I've been working through Apple's SwiftUI Tutorial over the past few hours and have made good progress, but now I'm stumped. I'm attempting to implement the "favorites" user input field within LandmarkRow.swift and continue getting the error…
Nick
  • 29
  • 2
-1
votes
1 answer

How to append an identifiable struct list?

struct Gg: Identifiable{ let id: Int let task: String } struct ContentView: View { @State private var items = [Gg(id: 1, task:"take the trash out"), Gg(id: 2, task:"Go for a run")] var body: some View { AddTaskUIView(title: "Add…
Na el
  • 75
  • 9
-1
votes
1 answer

How do I use .filter for an array with structs in Swift?

I am setting up a UISearchBar for my mathematics app. The search bar is supposed to search through an array allItems to find what the user is searching. The array allItems uses a struct called Headline to define an item ID and an item Title. When I…
-1
votes
1 answer

Parsing array with {"Name": String, "Value": String} structure in Swift 4

I need to parse in Swift a data structure similar to this (based on a JSON): [ { "Name": "uniquename", "Value": "John" }, { "Name": "locale", "Value": "UK" }, ] I stored this node in a struct like this struct Rowset :…
Nicola Bertelloni
  • 333
  • 1
  • 3
  • 17
-1
votes
1 answer

How can I init a struct from the values of a different struct

I have a user profile I am storing with a struct shaped like struct Profile: Codable { let company: String? let country: String? let createdDate: String? let dateOfBirth: String? let department: String? let email: String? …
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
-1
votes
1 answer

iOS Swift. Capturing properties inside Closure in struct constructor

I got some issue with closure/struct/capturing properties. I can't really explain the architecture but i need to have something like this: class ControllerAAA { struct Events { var userDidSelect(_ controller: Controller) -> ()? …
Nek
  • 73
  • 8
-2
votes
1 answer

How do I make a struct with nested json?

I have a JSON response from my api that returns this: [ { "id": 1, "chapter": 5, "amount": 28, "texts": [ { "lyric": "lorem ipsum", "number": 1 }, …
erikvm
  • 858
  • 10
  • 30
1 2 3 4
5