45
votes
Accepted
Is this FizzBuzz Swift-y?
Is this FizzBuzz Swift-y?
Kinda, but it could be a lot better. Here's what I would do to fix it:
Extrapolate this code into a method, then call the method from the ...
32
votes
Accepted
Rewrite code from Objective-C to conform with Swift power tools and concise style
The problem here isn't that your Swift looks like Objective-C. The problem is that, because you're developing a toy app, you've used a toy design, and now you don't like the toy design. Probably you ...
28
votes
Accepted
Stack implementation using Swift
Let's start with some general remarks:
Swift does not require semicolons after statements (but they are allowed). From what I have seen since Swift was introduced last year,
most people do not write ...
25
votes
20
votes
Accepted
Swift iOS - Call back functions
Very regularly when dealing with asynchronous stuff (among other things) in iOS development, we have to make a decision between three tools.
Closures (blocks, callbacks, etc)
...
19
votes
Ultimate FizzBuzz
Your code looks good to me, and I have only some minor remarks and
suggestions.
An Optional has an implicit initial value of nil, so
...
18
votes
Accepted
Int extension for translating integer to plain English
So Apple already has an implementation for this, using NSNumberFormatter. A bit easier to implement than what you have now ;).
...
18
votes
Swift 1.2 Singleton Implementation
First and foremost, printing text to the console is absolutely pointless for an iOS application. It's okay to do it as an easy way to test whether our code is working as intended, but we don't want ...
17
votes
Accepted
Piano app in Swift
I think this should work. The key (pun intended) to making this work is to take advantage of the tag property of UIButton. In ...
16
votes
Accepted
Project Euler #2 (Even Fibonacci numbers) in Swift
The following is similar to Flambino's approach, but creates a Swift
SequenceType so that you can use the Swift library functions
...
16
votes
Accepted
Getting WiFi SSID on iOS in Swift
The first thing that stands out to me is that you've created an entirely new class that exists purely to have this class method. This doesn't make a whole lot of sense. At a minimum, this method ...
15
votes
Dot product, ported from C to Swift
You can remove the size parameter as arrays know their own size in Swift, and use the zip, ...
14
votes
14
votes
Accepted
Extending CGPoint to conform to Hashable
I can see no advantage of computing the hash value from Int(self.x) and Int(self.y). As you already noticed, truncating the ...
13
votes
Accepted
Parse query checks and increments
Lately, when writing Code Review posts, I like to point out the first thing I notice when I look at someone code.
This is the first thing I notice when I look at your code.
Without looking at ...
13
votes
Accepted
Mocking UserDefaults in Swift
So first, as CAD97 rightly points out, if you simply define your protocol as identically matching the methods from UserDefaults you intend to use, then making ...
12
votes
Is this FizzBuzz Swift-y?
In a for loop in Swift, the parentheses are optional, and from all of Apple's book and sample code, they are usually omitted--you did so yourself on the ...
12
votes
Accepted
Project Euler, Challenge #5 in Swift
== false
while found == false
We'd prefer to see either this:
while !found
or this:
<...
12
votes
Accepted
Fibonacci in linear time by using an extra pointer
Your function uses global variables, which is bad for several reasons:
The variables must be reset before the function can be called again.
The variables can be modified from outside of your function,...
11
votes
Project Euler #2 (Even Fibonacci numbers) in Swift
I can only suggest a faster* math-based algorithm:
The fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 and etc.
The even ones are: 0 at index 0, 2 at index 3, 8 at index 6, 34 at index 9 and ...
11
votes
Beginner stopwatch app
The primary problem I see here is the way we're keeping track of the time passed. NSTimer is not guaranteed to tick with the exact amount of time you passed it. ...
11
votes
Background execution in iOS
func backgroundExecutable(f: (() -> Void) -> Void) -> (() -> Void)
This is madness and it takes a number of mental gymnastics to figure out what is ...
11
votes
Accepted
Prime Number Generator in Swift
That is not the Sieve of Eratosthenes
The Sieve of Eratosthenes computes multiples
of each found prime to mark subsequent composite numbers in the sieve.
Your algorithm computes the remainder of all ...
10
votes
Project Euler, Challenge #5 in Swift
You are using a brute force attack to solve this problem but you should better think about it and use some maths.
Right now you are checking if the number is evenly dividable by ...
10
votes
Accepted
Reading bytes from packet
One things for certain... an array of tuples which is basically being used as a glorified dictionary is never going to suffice as an acceptable data model. Moreover, an array of bytes isn't really ...
10
votes
Accepted
On Knuth's "Algorithm L" to generate permutations in lexicographic order
Optimising the functional approach
Iterative vs functional approach: Is it possible to use the (existing) functional methods without losing performance?
I don't think it's possible to use the ...
9
votes
Accepted
Checking two text field for match and checking for null
Your indentation is a bit wonky. Why is the first line indented? Why isn't the stuff in the inner-else indented correctly?
There's no reason to println() our ...
9
votes
Accepted
Sprite-Kit/Swift game
You've posted quite a lot of code, and as such, for now I'm going to focus simply on a big picture overview of your code (and its organization).
This is the first thing that stands out to me is that ...
9
votes
FizzBuzz in Swift 2
I would have started by looking over more than just the question in the linked question. You should have looked at the answers.
First of all, while the added where...
9
votes
Accepted
Coredata delete all data in an entity
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext!
The type ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
swift × 665ios × 218
performance × 50
programming-challenge × 45
swift3 × 44
beginner × 38
strings × 26
array × 26
object-oriented × 24
algorithm × 22
json × 22
uikit × 21
design-patterns × 20
cocoa × 20
generics × 19
functional-programming × 14
protocols × 14
swiftui × 14
time-limit-exceeded × 13
comparative-review × 13
mvc × 13
core-data × 13
primes × 12
image × 12
calculator × 12