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.

learn more… | top users | synonyms

0
votes
0answers
35 views

Swift-like extensions in Java using inheritance

After picking up some Swift skills with Java as my strongest language, one feature of Swift that I really like is the ability to add extensions to a class. In Java, a pattern I see very often is ...
-1
votes
1answer
79 views

Best approach to learn OpenCV to use with Swift? [on hold]

I am trying to figure out how to use OpenCV with XCode's Swift. I need to do realtime video processing for the project I am working on, but I can't seem to find any good references on learning OpenCV ...
0
votes
0answers
18 views

Design for keeping local user profile data in sync with the server

So I'm working on an iOS app and I’m thinking about how to keep user profile data in sync between server and client. The first idea that comes to mind is to create a class called User. It would be a ...
-1
votes
1answer
112 views

What's the point of Swift's function notation?

Why does Swift use this function notation: func greet(person: String, day: String) -> String { return "Hello \(person), today is \(day)." } Like, I don't get why it uses the small arrow -> ...
1
vote
1answer
13 views

Parsing a UITextDocumentProxy in Swift 3

I'm currently developing a custom keyboard app and am having trouble parsing what the keyboard has outputted onto the text document proxy. How does one go about this? I feel like I'm losing my mind. ...
1
vote
1answer
65 views

Design for iOS app backed by API

I was wondering if anyone out there has general tips for how to structure an iOS app backed by a REST api. There are basically two approaches to this that I've thought of API calls placed ad hoc in ...
3
votes
0answers
66 views

When should bool.boolValue be used?

Recently a co-worker has taken to checking boolean values in the following manner: if boolVar.boolValue { ... } These variable are generally declared explicitly as boolean types either using: ...
1
vote
0answers
86 views

How to avoid repeating a condition in methods that use it differently?

Let's say I have an app that displays details for a person. Each person can have zero or more phone numbers and zero or more notes attached to it. Thus, I have a Core Data entity Person with one-to-...
0
votes
1answer
40 views

What's the answer to my Unit Testing dilemma when setting up mock dependencies?

I am trying to implement VIPER architecture on iOS in Swift. The problem I have is how to set up the object graph. Please ignore the Router and the Entity as it is not relevant to my problem. That ...
6
votes
1answer
147 views

Why does Swift need witness tables?

I'm trying to read up on implementation details of Swift, and one thing I can't nail down are its "witness tables". It looks like they're a separate vtable pointer used for structs. But why would you ...
1
vote
0answers
88 views

What is the preferred way to check if an optional has a value without using it?

Which of these is the ideal way to check if a value exists without caring exactly what its value is? if let _ = flags[.showField] { showField() } if flags[.showField] != nil { showField() } In the ...
7
votes
3answers
100 views

Why does Swift initialise subclass proper fields first?

In language Swift, to initialise an instance, one has to fill in all of the fields of that class, and only then call superconstructor: class Base { var name: String init(name: String) { ...
3
votes
2answers
206 views

Alternatives to the delegation pattern allowing blind messages between components

Delegates and delegation exist to enable passing specific messages to an observer, regardless of that observer's type. In a coordinator-type architecture, where coordinators manage and run the flow of ...
1
vote
3answers
384 views

Is there such a thing as Protocol Oriented Programming?

I am copy/pasting my comment from this article sumarizing a post on reddit: I really don't think "Protocol Orientation" is something new... You've got protocols in Obj-C, you've got Interfaces in ...
2
votes
1answer
87 views

Sorting a Data Set with multiple 'Tie Breaks'

I'm currently working on a software project that requires several different types of sorting mechanisms. I have been searching, to no avail, to find an algorithm to do a sort with tie-breaking. In ...
0
votes
2answers
60 views

NSUserDefaults, Core Data or neither?

Everytime I press a certain button, it should remove a random index from a dictionary and then save that dictionary everytime its modified. I have done this using NSUserDefaults. I have found that ...
2
votes
3answers
263 views

Why doesn't the compiler assume the if statement condition is correct inside it?

First off all: sorry for the title, but I didn't now how to better formulate the meaning of my following question in a single phrase. While I was writing the following Swift code: if errorData....
4
votes
4answers
427 views

JSON API or Plain JSON

There is a debate in my company on whether we should use the JSON API specification or stick to plain JSON for developing APIs that will be consumed by mobile apps, mainly iOS and Android. One ...
0
votes
0answers
78 views

Best architecture for customising the character

I want to customize the game character before starting the level, for example, select what kind of weapon, armor, clothes, etc. There are several components and each component consist of several types....
4
votes
1answer
93 views

Protocol vs Generic

I have a class that uses a type, but it doesn't need to know anything about that type. In Swift, I can code this up one of two ways: protocol Type { } class Class { // use Type } or class ...
3
votes
1answer
176 views

Why closure declaration syntax in Swift is different from function declaration

let closure = { (args) -> ReturnT in ... } v.s. func function(args) -> ReturnT { ... } Why didn't Apple follow principle of Occam's razor and make closure and function declarations to be ...
2
votes
1answer
157 views

What are best practices when it comes to extensions in Swift with reusability in mind?

I like the Swift way of trying to eliminate unintended consequences wherever possible. Whenever there is a change to the language that deprecates something I have been doing for years, it forces me to ...
2
votes
2answers
443 views

What did the reviewer refer to in this code review?

I sent the code for a job application and got the following review: Regarding the Project Structure: Physical separation is absent. Logical separation is present but not up to best practices. Things ...
0
votes
1answer
75 views

iOS: How to switch between prod and non prod REST end points

A noob iOS dev question: How do iOS developers develop their app with non prod REST URL endpoints while then using a prod REST URL endpoint for actual use by customers? I'm not aware of a way you ...
0
votes
1answer
196 views

multiple api calls vs more complex apis

I have been providing a Web API (.NET MVC 5) of an Oracle Database to people who are making a mobile app. I have to admit that I am not very good at it. I have found that I can easily produce Data ...
1
vote
2answers
212 views

swift typealias vs empty inherited class

I am working on JSON model classes in a swift project. Examples of the sample JSON and classes are below. In the JSON response, there can be many different unique statistics returned, but they all ...
4
votes
1answer
181 views

Extension versus Delegation

I am using Swift and am wondering about the concepts of Extension and Delegation. Recently I found a case where either one of these two concepts could be applied. This reminded of the "composition ...
0
votes
1answer
127 views

Could this class be considered as a Factory class? [closed]

I've recently worked on a reusable network service class for a service-aggregator iOS app. This class should retry a failed request if it was caused by expired user token. Plus, this class will be ...
12
votes
5answers
1k views

Swift functions vs computed properties

Say I have have a class Event as follows: class Event { private var attendees: [Person] = [] // Case 1 //******* // Should I use a func… func countOfAttendees() -> Int { ...
1
vote
2answers
225 views

What does “Linux Ready” mean in the context of a project written in Swift?

There are few GitHub repositories written in Swift that are presented to be "Linux Ready". The Zewo organization has several repositories identified as "Linux Ready". What, exactly, does this mean?
8
votes
1answer
1k views

For what reasons would you use a separate class extension for each delegate in Swift?

I was working through a Ray Wenderlich tutorial and noticed that the author uses class extensions to hold delegate callbacks rather than having them be handled in the class itself i.e.: delegate ...
1
vote
1answer
573 views

How should I handle the fetching of cached data in iOS

I'm developing an app at work, this is my first big application and in my smaller projects I didn't use caching at all. What's currently happening When the user logs on for their very first time ...
0
votes
1answer
120 views

Swift: Creating an empty array [closed]

The following: var emptyArray = [String](); What do I need the parentheses () for? [String] says, that the array accepts strings only. But why do I have to put the () there?
10
votes
2answers
2k views

Why does Swift not require semicolons? [closed]

I normally code in either c# or Objective-C and recently took it upon myself to learn Apple's new programming language - Swift. The first thing I noticed is that you don't need to add semicolons to ...
-1
votes
1answer
135 views

Global counter using iOS and Parse? [closed]

I'm very new to Parse and trying to set up what is basically a voting app where I can collect data on how many times all users have pressed a button. I found some information on Atomic Increment ...
0
votes
0answers
75 views

How to ensure this constraint at compile time?

I have an interesting constraint/invariant and I would love to hear people's input on how to maintain it. Big bonus if it can be ensured at compile time... I have the types below, and the following ...
2
votes
2answers
378 views

Testable design in Swift

I've been searching for so long about how to design testable classes in Swift but every information site just describe basic stuff like how to test, how to assert, why is testing good... My current ...
4
votes
1answer
347 views

MVVM: Should the VM be a value type?

I have been recently strongly influenced by two lectures: Gary Bernhardt's "Boundaries" (https://www.destroyallsoftware.com/talks/boundaries) and Andy Matuschak's "Controlling Complexity" (https://...
41
votes
10answers
11k views

Why would a program use a closure?

After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure? ...
15
votes
3answers
14k views

How does garbage collection compare to reference counting? [duplicate]

I starting working through an online course on iOS development in the new language from Apple, Swift. The instructor made a point that raised this question in my mind. He said something to the ...
1
vote
1answer
222 views

Best architecure approach to develop iOS app

I'm trying to create a calendar app similar to this design: Calendar Design I'm currently using this calendar framework: CVCalendar and it's working great, but my question is, what do you think is ...
1
vote
2answers
242 views

Is there a detriment to using SQLite over a pList for persistence?

I'm making a fairly simple application and I've got a settings menu that stores times and some boolean values. I have the application storing and retrieving data already but I started to wonder if ...
3
votes
1answer
370 views

Static properties and implicit “self” property in structures and enumerations vs classes in Swift

I am currently reading the Swift language documentation and came across these sentences in the chapter about methods: Similarly, type methods on structures and enumerations can access static ...
3
votes
1answer
1k views

Would I rather use Core Data or save files to the system?

I'm developing an iOS app which basically fetches a JSON from a remote location, parses it and instantiates classes for a couple of its elements. For some visualization, this should give you a basic ...
3
votes
3answers
1k views

Decorator design pattern in swift

Im reading "Head first design patterns" (here you can find exact example mentioned in book) While going through Decorator design pattern, everything was crisp and clear until i stumbled into this ...
3
votes
1answer
386 views

Ways to do callback, when and where

I've recently started to do some more complicated programming with network-related work on iOS with Swift. This introduced a lot of asynchronous code not only in networking but also some exchange of ...
1
vote
2answers
715 views

Workaround for unit testing Core Data in Swift

I am still pretty new to programming, but my first app was recently approved and is now for sale on the App Store. My app uses Core Data and is written in Swift. After some initial difficulties, I ...
5
votes
3answers
4k views

Using the optional 'self' reference in instance methods in Swift as a matter of style

Swift allows optional prefixing of method calls and property references to the current object instance via self. Removing these prefixes can declutter code but, depending on the length of the method ...
3
votes
1answer
2k views

Usage of MVVM in iOS

I'm an iOS developer and I'm guilty of having Massive View Controllers in my projects so I've been searching for a better way to structure my projects and came across the MVVM (Model-View-ViewModel) ...
29
votes
1answer
9k views

Swift Protocol Naming Conventions [closed]

Coming from a mainly c# background, I'm used to using the term "interface" for describing an object with no implementation that defines behaviour. In c#, the convention is to prepend interface names ...