Questions tagged [swift]

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS.

Filter by
Sorted by
Tagged with
4
votes
2answers
83 views

Reducing a list of points into a list of pairs of points

I have some data… let points = [(718, 620), (4596, 1280), (410, 333), (4597, 993), (410, 337), (4597, 996), (428, 337), (4597, 1000), (431, 335), (4599, 1044)] …...
4
votes
1answer
136 views

“What To Do” App

I am starting to build up my portfolio, so I am starting to build projects whenever an idea pops up in my head. So, I decided to build an app that helps you decide what to do. Basically how it works ...
4
votes
2answers
7k views

Removing a subview with a subview from a UIView without memory leaks

I made a custom UITextView for vertical Mongolian writing. It is made by subclassing UIView, which has a subview called ...
4
votes
2answers
341 views

Swift main thread style

I run into issues where I forget to run UI changes on the main thread. I've just fixed an issue for loading and unloading an activity indicator and fixed it with the following code: ...
4
votes
2answers
2k views

Parsing and converting DMS Coordinates from String to Double

I have some coordinates looking like N47° 15' 36.75",E011° 20' 38.28",+001906.00 and I've created a class to parse and convert them to Double: ...
4
votes
2answers
272 views

Translating Objective-C use of static and +(void)initialize to Swift

I am converting an old Objective-C class into Swift. My actual question is at the very end after all of the code. Here is a cut-down version of the Objective-C class: DateInfo.h: ...
4
votes
1answer
517 views

Ring Timer Animation with Chasing Tail using CoreAnimation

After a fair amount of trial and error, I have gotten the animation acting in the manner that I want it, as seen here. However, I always feel like I'm writing way too much and too sloppily when trying ...
4
votes
1answer
315 views

Wrapping the iOS triple buffering procedure in a generic swift class

In the Metal sample code and best practices guides it is advised to use a triple buffering technique to avoid access conflicts between the cpu and the gpu. The required code to do so requires ...
4
votes
2answers
3k 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 ...
4
votes
1answer
12k views

Swift FloatingPoint rounded to places

I'm playing a bit with extensions for default protocols in Swift 3.0. I would like to implement rounded(toPlaces places: Int) -> Self for ...
4
votes
1answer
117 views

Safe init using failable guarded initializer

I am wondering if that is a safe and proper init, with one failable init guarded and an init. Are the force-unwrap correct in the self.init as I know they are ...
4
votes
2answers
5k views

Recursive function to show directions for multiple locations

I have a Mapview which shows a bunch of locations (Events). Here's the code of an Event object. ...
4
votes
1answer
965 views

Second attempt at Hangman in Swift

I recently posted my Hangman game, and got some amazing feedback! The main thing suggested was to create a word generator that could read JSON files so that my hangman brain class didn't have to ...
4
votes
2answers
185 views

Fetching the definition of a word using a REST API

This is the code I'm using to GET the definition of a word from Wordnik's REST API. I don't want to ignore any error but this is causing the code to be ridiculously long. I'm new to Swift so I'd ...
4
votes
1answer
847 views

Optimization of multiple arrays for filtering

My app will be running on an iPad with A7. I pass in 3 JSON arrays and right now do some simple filtering, in the future the operation will be much more complicated. I realize the ...
4
votes
3answers
5k views

Project Euler #8 - Largest product in a series

I just finished Project Euler #8 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The four adjacent digits in ...
4
votes
1answer
352 views

Project Euler #6 (Sum square difference) in Swift

...
4
votes
1answer
309 views

Find minimum count of items where sum of them is X from an array

I recently faced an interview question where you have to find minimum needed items from an array that can added together to generate X value. For example giving: <...
4
votes
1answer
397 views

Parse data into an array of structs

I'd had a hard time getting this to work. I’d like to parse a file containing data and copy this data into a struct. The data file (test.dat) looks like this: <...
4
votes
1answer
361 views

Leetcode 102: Binary tree level-order traversal in Swift

102. Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary ...
4
votes
1answer
3k views

Iterating 2D array in Swift

I have a situation where I needed to convert NSNumber 2D array to Float 2D array, so I did it like this: ...
4
votes
2answers
799 views

Big Nerd Ranch Bronze Challenge: Disallow Alphabetic Characters

I just completed BNR's bronze challenge for disallowing alphabetic characters, and would love some feedback on what I did right and wrong, and how I can improve my code for reusability and ...
4
votes
1answer
308 views

Counting the total value of Card instances given

I am trying to write a function called countHand() that takes in an array of Card instances and counts the total value of the ...
4
votes
1answer
593 views

Rock Paper Scissors in Swift

I'm going through the eBook Intro to App Development with Swift by Apple and I am making the Rock, Paper, Scissors app in lesson 20. This is the assignment that I got: [...] Name the enum ...
4
votes
1answer
97 views

Swift Prim's algorithm

Lots of Prim's algorithm implementations seem long, and rely on a priority queue implementation. If I use an adjacency matrix I can then calculate the next item to take using functional programming ...
4
votes
1answer
297 views

Custom caching class in Swift

I'm using Swift 4.0 and I'm using UserDefaults in my project for storing Strings like login or something. I have a class: ...
4
votes
1answer
2k views

A consumable byte array, in Swift

For decoding binary data (in my case, delivered by a Bluetooth device), I've written this struct: ...
4
votes
2answers
231 views

Initializing an Array of Alternating Values

My goal in this project is to make something that can—as, quickly, effectively, and efficiently as Array(repeating: , count: )—initialize an ...
4
votes
1answer
248 views

iOS Swift 3 app that requests data from the Stack Exchange API

This is my first Swift app, so I want to improve everything that I can about my code and know what I can do better. The app requests 10 developers from StackExchange API and displays them in a table ...
4
votes
1answer
552 views

Writing a chunk of a file to a socket in Swift

I'm writing a chunk of a file from an offset to a socket. This is my implementation and it's working OK from my tests. Any comments or speed improvements? ...
4
votes
1answer
5k views

Finding consecutive days in an array of dates

The problem: How to get the largest number of consecutive days from an array of unknown number of Date objects, by taking into account days only like 4th of April, 5th of April and so on. Example ...
4
votes
2answers
14k 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 ...
4
votes
1answer
2k views

Swift Hackerrank 2D Array

I solved this question in Swift, but was wondering if there is a better way or if my code can be improved: Given a 6x6 2D Array: ...
4
votes
1answer
10k views

Show and hide views

I have some buttons in my class that show or hide two views (by setting their alpha property to either 0 or 1) when the user taps on them. I have written a function that uses the ...
4
votes
2answers
2k views

Swift solution to Leetcode “Longest Substring Without Repeating Characters”

From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
4
votes
1answer
3k views

Greyscale converter performance in Swift

I have a single class which converts an image's colors into greyscale (except one given color, which will be left as it was before): ...
4
votes
1answer
331 views

ReactiveCocoa implementation of async function

I would like a review of the RAC implementation for the function setGist() I've posted the code on GitHub for easier reading. Description: You create an instance ...
4
votes
1answer
22k views

Swift extension: Dictionary<String, AnyObject> to JSON string for URL parameter

Here's a quick extension for [String: AnyObject] dictionaries in Swift. The output needs to be in the following format (order and spacing don't matter): ...
4
votes
1answer
727 views

Save File Manager

I made a class to manage saved file in drive with Swift, and I tried to do the best work. Can someone get me a feedback about this class? What can I improve? Is this a good way to save a file? ...
4
votes
1answer
445 views

Project Euler #16 in Swift - Power digit sum

I just finished Project Euler #16 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. 2^15 = 32768 and the sum of ...
4
votes
1answer
99 views

POC for GithubUserFinder

I would like to request iOS developer community to please review my POC i.e. [GithubUserFinder][1] which I have created as part of job screening test at T-mobile Bengaluru. I have around 2 years of ...
4
votes
1answer
87 views

Force-unwrapped property as a contract

I have a class, which is meant to show a full screen modal controller with a set of actions (apart from actions it also has some static content, a lot of labels and images which are irrelevant, so I ...
4
votes
1answer
204 views

Convert String to Integer (calculator app)

I'm currently learning Swift and today I created my first application, a simple calculator. My main goal was to practice and create something without any help. After a few hours my application was ...
4
votes
1answer
170 views

Search a string for barcodes but ignore certain characters

I had to write a string search function that would search for barcodes, and be forgiving of minor formatting differences. For example, the barcode may be entered as ...
4
votes
1answer
868 views

Jumping on the clouds

I have started the Hackerrank interview preparation kit. The first problem I have solved with Swift is as follows: Emma is playing a new mobile game that starts with consecutively numbered clouds. ...
4
votes
1answer
712 views

A helper class for creating icons from a PNG image and colour in Swift

I have made a helper struct in Swift that creates circular icons from a PNG image (a white icon on transparent background) and a background ...
4
votes
1answer
837 views

Drawing a word, with a box around one letter

I'm working on a draw function which needs to draw the word 'crux' in the center of the current view and then draw a red box around the 'x' character like this: My ...
4
votes
1answer
830 views

Maintainable networking layer architecture

There are so many different solutions and examples on how to build a proper networking layer, but every app has different constraints, and design decisions are made based off trade-offs, leaving me ...
4
votes
1answer
9k views

Creating a array of custom objects from JSON, sent using PHP from a MySQL database

I'm using PHP to send data in JSON to create an array of custom objects in Swift. I've been told retrieveData() is bad code because it's in an infinite loop. I'm ...
4
votes
3answers
19k 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 ...

1 2 3
4
5
13