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.
2
votes
0answers
68 views
Alternatives to the delegation pattern
Delegates and delegation exists to enable passing specific messages to an observer, regardless of that observers type. In a coordinator type architecture, where coordinators manage and run the flow of ...
-3
votes
0answers
41 views
Hello World app size comparison [duplicate]
I compiled the standard "Hello, World!" program in three different languages: C, the new Swift and C++, using Xcode 7.3.1.
C code
#include <stdio.h>
int main(int argc, const char * argv[]) {
...
1
vote
2answers
204 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 ...
2
votes
1answer
64 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
30 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 ...
1
vote
3answers
235 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
291 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
74 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
78 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 ...
2
votes
1answer
115 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
99 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
427 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
61 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
145 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
149 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
142 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
120 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 ...
10
votes
5answers
635 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
203 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?
7
votes
1answer
722 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
458 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
91 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?
9
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
119 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
72 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 ...
1
vote
2answers
341 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
274 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://...
40
votes
10answers
8k 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?
...
11
votes
3answers
10k 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
215 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
191 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 ...
2
votes
1answer
330 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 ...
2
votes
3answers
840 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
322 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
656 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
3k 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) ...
23
votes
1answer
7k 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 ...
32
votes
6answers
9k views
Why design a modern language without an exception-handling mechanism?
Many modern languages provide rich exception handling features, but Apple's Swift programming language does not provide an exception handling mechanism.
Steeped in exceptions as I am, I'm having ...
34
votes
2answers
5k views
Do modern languages still use parser generators?
I was researching about the gcc compiler suite on wikipedia here, when this came up:
GCC started out using LALR parsers generated with Bison, but gradually switched to hand-written recursive-...
105
votes
5answers
52k views
How can Swift be so much faster than Objective-C in these comparisons?
Apple launched its new programming language Swift at WWDC14. In the presentation, they made some performance comparisons between Objective-C and Python. The following is a picture of one of their ...