Questions tagged [swift-class]

25 questions
4
votes
0 answers

When to use class over struct in swift ? What Design Pattern is best Protocol oriented programming or Object oriented programming in Swift?

I know this question can be considered as "too broad", but if some of experts can give me the idea or guidance about this question then it will be very helpful to decide which design paradigms I should use ? I have created number of projects…
Wolverine
  • 4,264
  • 1
  • 27
  • 49
2
votes
2 answers

How to update the values of a struct in a View

In SwiftUI I have a struct that want to hold data of the View. Let's say there is a View that user can create a recipe in it. It has a text field to type the recipe name, and options to choose and add to the array in the struct's properties. I…
Danny
  • 129
  • 1
  • 8
2
votes
4 answers

How to change property value with static method?

In this simple game there is a class Fighter whose purpose is to make two fighters fight. The one who looses health below 0, it looses the game. In order to fight there is a static method fight (..) which iterates till one fighter wins the game,…
Fausto Checa
  • 163
  • 13
1
vote
1 answer

Generic struct 'ObservedObject' requires that 'Video' conform to 'ObservableObject' in SwiftUI

I'm trying to call an API and populate Data into List in SwiftUI, I'm a beginner in SwiftUI and I'm struggling with the error mentioned. I think there is some issue with my data model I've tried in the way I do normal API calls in swift Language,…
Akash Neeli
  • 337
  • 4
  • 12
1
vote
1 answer

Swift UI - ReferencerTester.swift File. Receiving Error while trying to append to an array

I am trying to add and instance of Class Wave to my instance of class WaveList I don't know why I am unable to simply append this within my Test File. My Classes look like this: class Wave { var name: String var country: String var type: String var…
ObamoDank
  • 141
  • 1
  • 2
  • 5
1
vote
1 answer

Unable to access class member inside the pod

Im accessing a variable inside a class of my pod. The members inside the class have internal access modifier. But cannot able to access the tenantURL from the networking class. Why this happens? SDKCore class public class SDKCore { public…
Vaisakh KP
  • 467
  • 1
  • 6
  • 25
1
vote
2 answers

Swift inheritance of singleton pattern?

Have this class which is never used directly, only inherited: class ApiBase {} How do I define a generic static singleton default here? - So I can: class FooApi: ApiBase {} // Want only one instance of `FooApi` class BarApi: ApiBase {} // Want…
A T
  • 13,008
  • 21
  • 97
  • 158
1
vote
1 answer

Swift class Inheritance output clarification

In the following code, why is myRide.drive() printing a class Car instead of "Driving at 200"? class Car { var topSpeed = 200 func drive() { print("Driving at \(topSpeed)") } } class Futurecar : Car { func fly() { …
user5570066
0
votes
0 answers

How to make a SwiftUI function update the style of certain buttons based on @published class variables?

I want to have up to 13 buttons (the amount of total buttons should be able to change later based on user toggles), up to two per row/HStack. Each button will be a choice option for a game, only one is the correct answer. This game is an observable…
TrappinNachos
  • 87
  • 1
  • 7
0
votes
2 answers

How a class has several methods with the same name?

I'm new to Swift. Making a pet project that works with Bluetooth Low Energy (BLE) devices. Thanks to Google found out how to run it (scan, connect etc). But still don't understand how it exactly works. The code is next: class BLEManager:…
NeMaksym
  • 33
  • 5
0
votes
0 answers

Value of a child from mirror introspection not conformed to protocol anymore

I am trying to understand swift's inflection capabilities. I have a parent Passport class whose child (User) implements a protocol Clonable, however when introspecting the child value, it fails the check child.value is Clonable. Can someone explain…
Wy th
  • 33
  • 5
0
votes
1 answer

How to send data with Protocols and Delegate with IBAction (Button click)

Hello I went across protocols and delegates in course recently (iOS dev guy in production here). I tried to apply this at my simple app, which basically do nothing, but I wanted to pass data from one VC to another. More…
user13406256
0
votes
0 answers

SWIFTUI - OberservableObject class being set to nill each time called

I am trying to learn Swift, and swiftUI. I have a class : ObservableObject called within a button. the class fetches some data, and stores it in a data var (an array of (string:any)) the class function fetch data is called within onAppear function…
Yann Massard
  • 283
  • 2
  • 16
0
votes
1 answer

How to have a Swift file that runs DB requests and return variables from views

I am trying to create a class that it runs a Firebase requests and saves the result in variables. Then from different views I access the variables. Each variable will be for one category. I have made a class in the same view as I am showing the…
Danny
  • 129
  • 1
  • 8
0
votes
1 answer

class in playground vs in program file

I have a question about something simple that works in Playground but not in a Project: (Playground code below) In the project where the class is in a separate swift file the code correction won't show me the the person.lastName and if I fully type…
RoGe
  • 19
  • 2
1
2