Questions tagged [swift3]

Use this tag only for questions directly related to changes in version 3 of Apple's Swift programming language.

2
votes
2answers
178 views

Tableview Subclass implementing delegate datasource

I have two view controllers which have same tableview. One is for Post and one is for Profile, which also contains a post by a user. I have decided to reuse the code, so I have created the class ...
1
vote
1answer
91 views

Swift UITableViewCell class to show cameras, ratings for a car wash and other information

I have an UITableViewCell class that written in Swift. And it seems to me that I did it the wrong way. It works fine, but I want improve the code or refactor it somehow to make it look better. Any ...
2
votes
0answers
103 views

Log in user through json and display the application

I am currently learning swift 4 and would like to ask you to correct my code. (I would like to have a pattern for learning the "beautiful code"). My code gets data from the server in JSON format and ...
0
votes
1answer
9k views

Prevent a UITextField from being input with aphabetic characters

The goal is to disallow typing alphabetic characters as input in a UITextField. Please tell me if this approach is convenient. ...
1
vote
2answers
645 views

Finding the number of perfect squares in an array

I am posting here for feedback about the code that I wrote to count the number of perfect squares in an array. ...
1
vote
1answer
58 views

Notifying view controller of changes to any of five types of models

I have a swift 3 project with a code that's look like very generic, but I don't know if I can reduce a method like this one : ...
3
votes
1answer
126 views

Project Euler problem #14 (longest Collatz chain) in Swift

This is my Swift code for finding the starting number, under one million, which produces the longest collatz chain. ...
3
votes
1answer
1k views

Basic Caesar Cipher in Swift 3.1

I have been learning Swift for the past day and thought I'd try a basic problem where I can do String manipulation. I am only on pg.100 of the Swift Programming Language on iBooks. Compared to python ...
1
vote
0answers
59 views

Weight Lifting App to calculate a One Rep Maximum

I'd like feedback on the main entity in the Core Data model of my "One Rep Max" weightlifting calculator. All feedback is appreciated and in particular, I'd like to know if I've done a decent job of ...
1
vote
2answers
124 views

Switching between queues in cellForIndexPath method

My tableView is scrolling very slowly because there is a fetch request done in every cellForIndexPath method. I have verified ...
1
vote
1answer
288 views

Grouping models without dictionary

I want to group an array of structs only using arrays into an array of new structs. In this example I want to group the Person structs by ...
3
votes
0answers
102 views

Load data from WebAPI to the ViewController

My current code working perfectly, it is for data load from web api to the UIViewController (UITableView). But I am confused ...
9
votes
0answers
888 views

Interview coding challenge for iOS Part 2 - the application in Objective-C and Swift

I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side of the products. The job description indicated they needed someone with 4 years of Objective-C and iOS ...
2
votes
0answers
176 views

Find MIDI devices with certain names and make them usable

I'm working on a Swift app for macOS, where I take input from MIDI devices and transform that input. The MIDI devices being supported come in for flavors. What my code does is scan for MIDI devices, ...
4
votes
1answer
4k views

Countdown timer in every table cell

I am making countdown app with multiple records, so I am using UITableView to show that records and countdown dates. What I do is just take one timer and reload cells on every second. Is this a best ...
6
votes
1answer
3k views

UIButton subclass with animated 'shimmer' effect

In earlier versions of iOS the lock screen had a 'slide to unlock' element which I'm referencing as a 'shimmer' effect. The effect I'm looking for is simpler: Button starts with single color (e.g. ...
2
votes
2answers
127 views

Loading data from a web API to be displayed in a tableview

In my object Dish xxx.Dish, I want to access the Choice class price and name to display . ...
5
votes
1answer
2k views

Swift 3 UIPicker

I have been making a little test app to try and learn Swift 3 / iOS better. I started a while ago with with Swift 2 but stopped, so getting back into it, but there is so much iOS to learn! It seems ...
2
votes
1answer
130 views

CommandLine StreamFormatTester

Using Chris Adamson's book Learning Core Audio I'm getting familiar with Core Audio for Mac/iOS. The code examples are 100% Objective-C. I'm trying to follow along using Swift 3. This small piece of ...
6
votes
2answers
231 views

Project Euler solution #2 using Swift 3

I just wanted some review and opinions. Any better implementations or suggestions would be great. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...
3
votes
1answer
349 views

Singleton class with custom initializer

In a Swift project, I have a class should be used as a singleton: ...
-4
votes
1answer
204 views

How can I clean my swift code [closed]

Here is my code . I am not sure is it best practice or not? Please help me to clean my code. I initial all value. Should O put all in optional ?. Is there any ...
1
vote
2answers
3k views

Find substring of a string in Swift 3

I am using this basic extension for a Swift project. It works well, but I want to make sure it is the absolute fastest way to get a substring. ...
0
votes
1answer
151 views

Simple HTTP API requests in an exam paper download app

So basically I am building an app that helps to download some documents via a rest api. Here is the SearchViewController ...
2
votes
1answer
265 views

Simple War game in Swift

I'm new to swift and I want to know if I'm doing something wrong or a harder way. I made a simple war game app. Tames of variables aren't correct, I know, but I was doing it quickly and I didn't worry ...
3
votes
2answers
11k views

Showing activity indicator (loading image) while processing in background

I have a login screen on my iOS app. When I click login button I want to make sure that user should be displayed a loading image in center of the screen. I found lots of different methods online but ...
3
votes
1answer
89 views

Optimal custom operator with generic type constraint for numerical type

I'm implementing (for an article) two custom infix operators: ¿% - to calculate percent of total %? - to calculate the percent ...
1
vote
1answer
499 views

Configure Table cell in model class

I'm trying to show data in UITablleView after getting it from an HTTP request. I heard that the best and professional way to do it is configure the cell and do the ...
3
votes
1answer
80 views

Transformations an array, combination of between map and reduce

I'm working on a function that reduces pairs of elements if they meet some criteria. For example, given an array: ["1", "2", "a", "b", "3", "4"] I want to ...
4
votes
2answers
10k views

Basic calculator in Swift 3

I just started learning the basics to Swift 3 about 2 days ago. Since then, I've decided to make a simple calculator that can only do one operation at a time. I was wondering how efficient this was ...
8
votes
1answer
1k views

Extending CGPoint to conform to Hashable

For Advent of Code Day 1, I found myself needing to use a tuple as a key in a dictionary. Seeing that I can't extend tuples in Swift, I decided to extend CGPoint ...
2
votes
1answer
2k views

Listening to IOKit events with Swift 3

This is my first program in Swift/Xcode. The full source code and xcode project is available in GitHub. The part I would like reviewed is IOKeyEventMonitor.swift. ...
1
vote
2answers
187 views

Checking for required text fields for login

I wrote this script and it's working quite well however I think there's too much if else statements on it. How could I change them for a switch statement? ...
2
votes
2answers
653 views

Checking an authentication decision in a JSON response

I've been working on this login screen logic. It checks for the parameters in the JSON response to decide which action to follow. It works but it's kinda ugly and verbose. Any suggestions to ...
3
votes
2answers
2k views

Swift 3 Generic fetch request extension

I implemented an extension for the NSManagedObjectContext that takes any CoreData class as a parameter and performs a fetch request on it. I am new to CoreData ...
0
votes
2answers
2k views

UIAlertController and input validation

I'm refactoring some "old" Swift code using deprecated UIAlertView and delegates. I have a UIAlertController with an input ...
11
votes
2answers
547 views

Quickselect algorithm in Swift

I recently answered a question on Stack Overflow about finding the k-largest element in an array, and present my implementation of the Quickselect algorithm in Swift for review. This is essentially ...
2
votes
1answer
693 views
3
votes
1answer
7k views

Displaying JSON data from a server in a UICollectionView

This code pulls JSON from a server and delivers some data like imageURL, titleString and ...
0
votes
1answer
107 views

Extract regex matches with non matching parts

I want to check a string by using multiple search patterns and split the string at every occurrence. I'm using RegEx and it works fine. But I'm worrying about efficiency and performance. ...
1
vote
1answer
8k views

Accessing a UIView's parent UIViewController using the UIResponder chain

I recently found a static C function on Stack Overflow which returns a UIViewController reference from a containing subview using the responder chain: ...
14
votes
0answers
225 views

Water flowing swiftly over farmland – The August 2016 Community Challenge

This is my attempt to solve the August 2016 Community Challenge in Swift. I tried to implement the algorithm described by @200_success: Each Cell keeps track ...
7
votes
2answers
407 views

Postponed Prime Sieve in Swift

Motivated by this question, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an a-priori upper limit (such ...
2
votes
1answer
667 views

Unbounded Sieve of Eratosthenes in Swift

I've spent a while teaching myself Swift, and decided to take on the challenge of writing an unbounded Sieve of Eratosthenes to challenge myself. This is actually the first time I've written an ...