2022 Developer Survey is open! Take survey.

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
0 votes
1 answer
35 views

SwiftUI View permissions best practice?

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 ...
user avatar
  • 11
0 votes
0 answers
12 views

Migrating from value semantics model stored on iCloud to Core Data model

I have an app that currently depends on fetching the model through CloudKit, and is composed of value types. I'm considering adding Core Data support so that record modifications are robust regardless ...
user avatar
-2 votes
1 answer
61 views

Store/Pass User data MVVM+C swift

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 ...
user avatar
  • 107
2 votes
4 answers
166 views

Swift: Best way to store crypto amounts?

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 ...
user avatar
  • 139
1 vote
1 answer
50 views

Guidelines for using extensions in Swift

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 ...
user avatar
  • 142
3 votes
1 answer
2k views

The right place for "app logic" in MVVM context

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 ...
user avatar
  • 141
1 vote
0 answers
38 views

Should I separate a variable that changes often into a different entity although it is contextually should be inside another entity?

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, ...
user avatar
3 votes
0 answers
519 views

Best practices for viewmodels for SwiftUI preview?

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 ...
user avatar
0 votes
0 answers
183 views

What would be a good approach to applying computer vision to automatically edit out the downtime in tennis video?

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 ...
user avatar
-1 votes
1 answer
399 views

Tableview cells repeating containing collection view Swift

I am having trouble presenting my tableview cells containing a Collectionview correctly. I want to display a different animal in each section based on the firebase data. My problem is about every 4 ...
user avatar
2 votes
3 answers
918 views

What is a good naming convention for Interface Adapters, Use Cases / Interactors, Entities?

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 ...
user avatar
1 vote
2 answers
405 views

Clean Code: How much architecture code should be written if architecture is supposed to be fluid

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 ...
user avatar
1 vote
1 answer
97 views

What is better way to track mistakes in error-prone part of a feature?

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 ...
user avatar
-2 votes
1 answer
69 views

Best way to deal with lots of nested closures in Swift

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 ...
user avatar
  • 364
2 votes
0 answers
57 views

What is the idiomatic Swift way to add general functionality via protocol/extension?

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 ...
user avatar
0 votes
0 answers
202 views

Common patterns for Observable data layer on iOS

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 ...
user avatar
  • 161
3 votes
1 answer
103 views

Need technical advice about passing data through UINavigationController

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 ...
user avatar
  • 33
-4 votes
3 answers
220 views

How to Replace Many if Statements for many types

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 ...
user avatar
  • 101
6 votes
5 answers
486 views

What is a good approach to naming when modeling a sport that can be between either individuals or teams?

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 ...
user avatar
0 votes
1 answer
114 views

Building native iOS app that runs on iPhone, iPad and Mac

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 ...
user avatar
3 votes
4 answers
279 views

Should a transformation function take a nullable and return a nullable or should the caller handle nullability

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 ...
user avatar
2 votes
2 answers
459 views

Localize a countdown timer

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),...
user avatar
  • 139
24 votes
3 answers
7k views

Struggling with cyclical dependencies in unit tests

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,...
user avatar
  • 3,118
3 votes
1 answer
3k views

What is a good approach for saving a Swift model that's a struct containing structs to Core Data?

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 ...
user avatar
2 votes
1 answer
57 views

At what size array in Swift would you consider switching to CoreData?

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 ...
user avatar
1 vote
0 answers
47 views

What is the advantage to inferred types *in Swift*? [duplicate]

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 ...
user avatar
1 vote
1 answer
56 views

Modular Quiz in Swift

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 ...
user avatar
0 votes
1 answer
39 views

Only be able to sign into app after existing user send invitation [closed]

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....
user avatar
  • 11
0 votes
2 answers
791 views

Does chaining higher order functions mean worse performance?

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 ...
user avatar
  • 101
0 votes
1 answer
123 views

One-field interfaces

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) ...
user avatar
0 votes
1 answer
106 views

What design pattern would help me make my factory more generic

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 ...
user avatar
  • 109
1 vote
2 answers
238 views

What is better approach to implement dependency injection using MVVM Architecture?

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:...
user avatar
4 votes
1 answer
1k views

Repository that performs API calls internally - DDD

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 ...
user avatar
  • 556
1 vote
2 answers
282 views

Reusable component with web service

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....
user avatar
  • 121
2 votes
2 answers
254 views

Where to put private computed properties?

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 ...
user avatar
5 votes
1 answer
303 views

How to break down complex if conditions that include optional binding?

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. //...
user avatar
10 votes
3 answers
2k views

Is it good practice to wrap a related set of properties into its own struct/class?

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 ...
user avatar
  • 323
5 votes
1 answer
539 views

Dependency Inversion Principle (Swift) - Applicable also without polymorphism? (Abstraction: constrained generics)

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 ...
user avatar
  • 201
3 votes
1 answer
624 views

Does swift value type like String, Array, Dictionary internally contain class

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 ...
user avatar
  • 141
5 votes
1 answer
3k views

Why doesn't Swift allow Int String subscripting and integer ranges directly?

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 ...
user avatar
  • 187
1 vote
3 answers
204 views

Should I write out computed vars that all depend on one other var, or should I assign them as normal vars in that single var's setter?

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 ...
user avatar
  • 824
3 votes
1 answer
1k views

What is the best way using swift 4/iOS to handle asynchronous requests eg. to Firebase Database? [closed]

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 ...
user avatar
  • 141
3 votes
1 answer
520 views

Why doesn't Swift's Numeric protocol inherit from the Comparable protocol?

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."...
user avatar
3 votes
3 answers
3k views

Are nested closures a good thing?

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 { ...
user avatar
1 vote
0 answers
125 views

Design choice: Use NSFetchedResultsController and store derived properties or roll my own data source?

I'm writing an iOS app in Swift that calculates a '1 rep maximum' weight using two inputs, weightLifted and repetitions. One of several formulas is used to perform the calculation with these two ...
user avatar
  • 147
-5 votes
1 answer
138 views

Trying to understand singleton objects in Swift [duplicate]

In Swift, if I have a class with only type properties and methods (everything declared static) would that be considered a singleton object? If not, why?
user avatar
  • 101
4 votes
1 answer
280 views

Use more dynamic dispatch could reduce compile time?

In swift the compilation time is really slow the amount of code in your project increases. So i was looking for ways to reduce that time. One approach maybe is to use language keywords like final or ...
user avatar
  • 57
7 votes
4 answers
3k views

Struct vs class in Swift

One of the stated reasons that structs can be more performant than classes is that no ARC is needed for structs. But suppose we have the following struct in swift: struct Point { var x:Float ...
user avatar
  • 247
1 vote
2 answers
222 views

Are there any downsides to creating a stub by subclassing in Swift?

I'm mainly interested in answers in regards to a Swift language, but more general answers are always welcome. I want to test a class (CUT), and for that I will use dependency injection. Now, I can: ...
user avatar
  • 127
2 votes
2 answers
525 views

Which one is more efficient; a subclass of UITableViewController for multiple purposes or multiple sub classes each for a purpose?

Say I have two views (Table View for example) that I'd like them to do different stuff; each loads different data but behaviors are similar for most par except what happens when a cell tapped for ...
user avatar
  • 123