Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [swift-language]

Swift is a programming language designed by Apple for creating iOS and OS X apps. Swift builds upon the foundation of C and Objective-C.

Filter by
Sorted by
Tagged with
2 votes
1 answer
380 views

In Swift, functions can be defined with named parameters, for example: func greet(person: String) -> String { ... } which need to be used when the function is called : greet(person: "Anna&...
DarkTrick's user avatar
  • 286
1 vote
1 answer
253 views

I'm developing a Swift Package distributed via Swift Package Manager (SPM). I have other dependencies (Swift packages) that my package depends on. Is it possible to expose types (classes, structs, etc....
Fourth's user avatar
  • 79
3 votes
1 answer
277 views

I am writing unit tests for my SwiftData application. Currently, I am using in-memory database, which get reset after every test. What benefits will I gain if I start using real database? My main ...
user19037628's user avatar
1 vote
1 answer
172 views

My team and I are beginning to mock our API responses in our iOS app so we don't have to worry about our backend being up when testing. I have conditional compilation directives based on the ...
Derek's user avatar
  • 121
4 votes
4 answers
1k views

I hope this isn't too off-topic/opinion-based, I'm new here. I want to pass three elements of the same type into a function. The three elements are unique cards of a deck of cards, so they're not ...
dve.exe's user avatar
  • 59
2 votes
1 answer
161 views

My question is regarding how would the developer know when you add interfaces/protocols to their code and inject them as dependency. Consider an example of BudgetService. protocol ...
john doe's user avatar
  • 141
3 votes
1 answer
191 views

What is correct in your opinion regarding the creation and handling of models in an application let's say using MVVM, or even an MVC design pattern? I will try to illustrate the situation I see at my ...
Lucas's user avatar
  • 139
0 votes
2 answers
2k views

I've got these classes: enum Environment { case staging case production static func current() -> Environment { #if STAGING return .staging #elseif PROD ...
Bawenang Rukmoko Pardian Putra's user avatar
1 vote
1 answer
408 views

I am currently developing an iOS application where there are options on the screen to edit and delete a list. Only the user who created this list can edit or delete it. I am struggling to determine ...
Trenton's user avatar
  • 17
-2 votes
1 answer
159 views

I have an app written using MVVM and RxSwift. For navigation I'm using coordinator What is the best way to store user's credentials and pass them to Network Layer. I don't want to sore them in DB or ...
Roma's user avatar
  • 107
2 votes
4 answers
321 views

Having a bit of trouble on deciding the best way to store crypto values which are usually in decimals. Do I go with Double or Float? Or is there an even better type that Swift offers? My initial gut ...
Tank12's user avatar
  • 139
2 votes
1 answer
167 views

The other day, I came across this question on StackOverflow. In short, the user who asked the question wanted to extend a class from a third-party library to implement the Codable protocol, but ...
TallChuck's user avatar
  • 152
9 votes
1 answer
10k views

I hope this is the right place to ask. I'm an experienced developer, and have used MVC for much time. This question is in the context of iOS/macOS development for the most part, (SwiftUI). Using MVC ...
Woodstock's user avatar
  • 201
1 vote
0 answers
44 views

So, I have an entity called Consultation that is being used as a member variable of the class VideoCallViewModel that goes like this: struct Consultation: Equatable { enum Status: Int, ...
Bawenang Rukmoko Pardian Putra's user avatar
4 votes
0 answers
1k views

Are there best practices about how to prepare lightweight viewmodels with dummy data, that could be used in SwiftUI previews? Right now, I have a viewmodel for an in-app purchase screen, that needs to ...
Tomáš Kafka's user avatar
0 votes
0 answers
231 views

I have an iOS/macOS tennis app that now lets the user import video, and I would like to add the ability to automatically edit out the significant amount of downtime where players are not in a rally or ...
Curious's user avatar
  • 95
4 votes
3 answers
3k views

I'm using MVVM + Clean Architecture in my app. And I sometimes don't have any idea if my namings are good enough for each Interface Adapters, Use Cases / Interactors, Entities. For View Models, it's ...
Bawenang Rukmoko Pardian Putra's user avatar
1 vote
2 answers
713 views

I watched a video series from Uncle Bob on Clean Code. He makes a few points on architecture which I both agree with but I believe could have clarification. From Uncle Bob: The Interactor is ...
Michael Ozeryansky's user avatar
1 vote
1 answer
133 views

That is quite specific circumstances I've come across, and I somewhat struggle to find proper way how to approach this. I'm given a class written in swift-language, which has a control property, like ...
Aleksandr Medvedev's user avatar
-2 votes
1 answer
344 views

I have some external SDK library that makes IO calls (either networking or database) in the form of blocks, like so: SomeClass.doWork(success: {}, failure: {}) Now I need to chain about 60 different ...
zaitsman's user avatar
  • 384
2 votes
0 answers
67 views

I am a scala developer new to swift. In scala we can share implementation across a variety of classes by "extending" a trait that has default implementations for the methods. I would like to see how ...
WestCoastProjects's user avatar
1 vote
0 answers
385 views

I am working on learning native iOS development in Swift, and I am trying to find something that is similar to what I've learned in Android development with Kotlin. In particular I am referring to ...
papafe's user avatar
  • 171
3 votes
1 answer
117 views

First of all a small introduction, im relatively new to Swift and to programming in general, been doing it for the last year and loving every and each new thing of this vast world. My post is about ...
ARams's user avatar
  • 33
-4 votes
3 answers
337 views

I have many dependent statements. What is the best approach to handle these cases dynamically? Example enum UserType { case buyer case seller } enum ViewType { case active case ...
a.masri's user avatar
  • 101
6 votes
5 answers
548 views

Tennis is played as singles or doubles. I considered making my tennis scoring model logic refer to "teams" throughout its naming since "player" wouldn't take into account doubles. However, seeing ...
Curious's user avatar
  • 95
0 votes
1 answer
258 views

Since Apple introduced Catalyst ealier this year during WWDC '19 it becomes possible to have a single codebase for an app that runs on iPads and Macs. Already for a long time it was possible to ...
Stan Reduta's user avatar
3 votes
4 answers
338 views

Often I need to transform a type to another, such as a networking model to a data model, or a data model to a binary representation. Should these transformation functions take an Optional/nullable ...
Michael Ozeryansky's user avatar
2 votes
2 answers
869 views

I have a very specific localization problem that I have not had any luck finding specific information about in my research. I have an app that I'm localizing that shows elapsed minutes(M), seconds(S),...
TheJeff's user avatar
  • 139
24 votes
3 answers
8k views

I'm trying to practice TDD, by using it to develop a simple like Bit Vector. I happen to be using Swift, but this is a language-agnostic question. My BitVector is a struct that stores a single UInt64,...
Alexander's user avatar
  • 5,195
4 votes
1 answer
4k views

I'm new to Core Data, and am not sure how to reconcile the need to inherit from NSManagedObject with the fact that my model is a Swift struct composed of structs. I chose to make my a model value type ...
Curious's user avatar
  • 95
2 votes
2 answers
104 views

I've developed a reading tracking app in Swift and for simplicity's sake I used arrays for my model. It stores some data about the books a user reads and a small image of the cover. I save them to ...
M. Chollar's user avatar
1 vote
0 answers
50 views

As I fool around in Swift I have come to absolutely hate variable declarations. int c = 0 seems easier to read than var c:Int = 0 and more informative than var c = 0, and int some() is radically ...
Maury Markowitz's user avatar
1 vote
1 answer
74 views

I've been working on the architecture of my Apps for a while. In the past I've used a SQLite database which I opened in the AppDelegate (Oh dear), and then created a global variable (really!) to ...
stevenpcurtis's user avatar
0 votes
1 answer
59 views

I am looking to build an app where the only way a new user can enter the app is if they have been invited by an existing user. Are there any API's, tutorials or resources that can help me achieve this....
iOSHG's user avatar
  • 11
0 votes
2 answers
1k views

For clarification, let's review the following example: Consider that we have the following array of Ints: let array = [1, 2, 3, 4, 5] and we've been asked to generate a new array from array ...
Ahmad F's user avatar
  • 101
0 votes
1 answer
163 views

I have an interface with only one title field: protocol Artist { var title: String { get } } (A) Should I pass the whole object as I did here: class Album { func setArtist(_ artist: Artist) {...
kasyanov-ms's user avatar
0 votes
1 answer
233 views

In my code I have 2 separate login types. I have a factory that decides which one to create based on an enum. Each login type has a different type of credential. Currently my factory method takes ...
dubbeat's user avatar
  • 109
1 vote
2 answers
254 views

I need to use DispatchQueue within controller and pass it as dependency. This is what I have tried so far and worked out two solutions. Need to ask what is better and in common use by other developers:...
Bartłomiej Semańczyk's user avatar
4 votes
1 answer
2k views

Please note: although my question relates to DDD, I am also interested in this from an architectural and OO design perspective. This question may also be a simple case of CQRS and/or interface ...
James's user avatar
  • 546
1 vote
2 answers
322 views

I am trying to create a reusable component / Cocoa Touch Framework in Swift that would display the current weather based on the user’s location. Right now I cannot decide which approach should I take....
SleepNot's user avatar
  • 121
2 votes
2 answers
399 views

In Clean code it's suggested that private helper functions should always exist directly below the function they're directly used within. Should I be doing this when using computed properties? It's the ...
Declan McKenna's user avatar
5 votes
1 answer
401 views

I've recently been reading Clean Code and there was a really nice example in java of when it is beneficial to break down a complex if statement condition in to a function rather than use a comment. //...
Declan McKenna's user avatar
10 votes
3 answers
3k views

Writing a User object in Swift, though my question relates to any strongly typed language. A User can have a bunch of links (FacebookProfile, InstagramProfile, etc). A few questions around this. Is ...
Prabhu's user avatar
  • 333
5 votes
1 answer
616 views

There exist a number of articles/blogs explaining the Dependency Inversion Principle (DIP) using Swift; to name a few (top Google hits): GitHub/ochococo/OOD-Principles-In-Swift - The Dependency ...
dfrib's user avatar
  • 201
3 votes
1 answer
897 views

I was watching WWDC video and can not understand when they talk about Even though all of these properties are value types, internally, they contain a class which is used to manage the lifetime of ...
maddy's user avatar
  • 141
6 votes
1 answer
4k views

If I have a string: let str = "Hello world" It seems quite reasonable to be able to extract a character: let thirdChar = str[3] However, that's not legal. Instead, I have to use the extremely obtuse ...
Duncan C's user avatar
  • 197
1 vote
3 answers
224 views

I'm using Swift, but I understand computed properties are a thing in a few other languages as well. I have the following case: var bar in class Foo is changed throughout program flow. vars a, b, c ...
Kevin's user avatar
  • 844
3 votes
1 answer
1k views

I've been using firebase database and now firestore for a while. I'm prob an intermediate level programmer and still at uni. I'm still a bit unsure re: the best way to handle calls that are occurring ...
Mike's user avatar
  • 141
3 votes
1 answer
621 views

I created a generic class MyClass<T: Numeric> {...} and got errors in my functions that tried to use > and <, along the lines of "Binary operator '>' cannot be applied to two 'T' operands."...
SaganRitual's user avatar
3 votes
3 answers
4k views

I've been doing Swift development for a while now with Firebase, and I find myself making a lot of code like this: Auth.auth().signIn(with: credential) { (user, error) in if let error = error { ...
Forest Kunecke's user avatar