Newest swift Questions

Q&A for professional and enthusiast programmers

How to get Video URL from Facebook Video id / share URL in Swift 3

I am trying to get the playable video URL from Facebook, Facebook doesn't give direct URL of video to play , instead its a URL with Video ID, I want to know if there a way to get Video URL using ...

Call completion block when two other completion blocks have been called

I have a function doEverything that takes a completion block. It calls two other functions, doAlpha and doBeta which both have completion blocks. These two functions should run asynchronously. I want ...

Simple In-App Purchase Request Swift 3

I am currently finishing up a mobile game for iOS that allows customization of the main character being used. To customize the character, users can select several different load-outs to purchase using ...

How to create a custom Slider control

I need to make a slider like this. It needs to stick to a line of text, and all texts need to be the same size no matter how long they are (one sentence could be a lot longer then another one) My ...

Can I create an app that record the music that my iPhone is currently playing? [on hold]

I try to learn Swift and I was wondering if it was possible to create an app that records the sound/music that my iPhone is currently playing. For instance, I'm listening to music, I launch my new app ...

Using PHCachingImageManager().requestAVAsset but causing app to pause swift 3

I am using PHCachingImageManager().requestAVAsset to load some videos from the camera roll: override func viewDidLoad() { super.viewDidLoad() print("SEGUE SUCCESSFUL") view....

How to keep an item in focus when switching to another another view in my tvOS application

I'm making a video app with collection views. My app can show a video of the selected cell in a collection view and it all works like the way I want it to be. When it shows a video the cell loses it ...

How to show temperature on map for all cities using swift [on hold]

all this is my first time asking a question. Ss there any way to show all temperature of the world in a map such as openweathermap has in here http://openweathermap.org/weathermap#. I have google but ...

Design Pattern for iOS apps [on hold]

Please suggest me pattern (MVC, MVP, MVVM or Delegate pattern or else) I should use for Universal app using Swift. Thanks in advance.

Swift 3 optional string to int

I am using Vapor for Swift backend. Following is the code i am working with. drop.post("postTodo") { request in var jsonContent: JSON? if let contentType = request.headers["Content-Type"], ...

IBOutlet is nil

I have created a standard outlet for a view that will hold different information based on the button selected on the previous screen. @IBOutlet weak var labelView: UIView! It shows it is connected ...

MBProgressHUD/MBProgressHUD.h' file not found

I only get this error when I build on my device (iPhone 6 and 5s). It popped up randomly today when I pod installed Firebase/Core. I've deleted it since. However, it works fine on the simulator. Can ...

Changing UserAgent of WKWebView after webView has loaded

Previous Title: Completely restarting a WKWebView after runtime I am trying to implement a feature that allows for the user to request a desktop site of a URL in the WKWebView. If I'm not mistaken, ...

How do you connect to AWS Cognito in Swift for user signing up and logging in?

I'm going to start this question by apologizing for such an open ended question, but I am really struggling and all the documentation is outdated. Amazon's provided sample app hasn't been updated and ...

Making Repeated Request to same API

I know how to make a regular API call using swift. What I am not able to understand is how to make the API call to be repeated until required. I want to call the API every one second API Call Code ...

Is whole-module optimization safe in Xcode 8.2?

In a previous version of Xcode, there was a bug with whole module optimization that caused apps to break. I believe it had to do with passing a closure to a dynamic framework, or generics in dynamic ...

Swift 3 Create Calendar, no local source even with iCloud off

I am trying to create a Calendar, not a calendar event but a Calendar. I cant get a local source and my app crashes. Here is my code: let newCalendar = EKCalendar(for: .event, eventStore: eventStore)...

Xcode 8 - How can I give the .app file to someone else to test

I have an Android developer, who has downloaded XCode. I just want to give him the app file to run in his XCode simulator. How would I get that to him and how would he "install" it in his iOS ...

how to control pagination with instagram API

I am developing a function which can use Instagram medias. According to Instagram API I have implemented the following code: let manager = AFHTTPSessionManager() var InstagramImage:[UIImage] =...

Convert JSON data to Double in Swift

I receive the following JSON response: { "id": 1, "value": 519.6365 } But when I convert the value to Double, I get: 519.63649999999996 How to keep the original value? (without rounding it) ...

Add custom icon to ShurtCutItem in Swift

Good evening! I've searched a lot but don't find a solution for my problem... let test = UIMutableApplicationShortcutItem( type: "testtype", localizedTitle: "Title", ...

TableView list folder‘s files(alomst .txt) and can click show details

I am trying to save something and list them with tableview, but its in a wrong way for me to use class to store them.So I choose when I save,at the same time create a file. Help plz:)

Quickblox tap message with picture [Swift]

I am implemented QuickBlox chat module with attachments. I want to take it a step ahead by adding a tap gesture. Whenever an attachment is send; I want to add a tapGesture to it so that it can open up ...

UIScrollView xcode 8 swift 3

This is my first question and I am brand new to coding. I'm creating an app and one of the pages has a form for a user to fill out with two labels, two textfields, a switch and a "send" button. For ...

unwindSegue slow to dismiss viewController

I am using an unwindSegue created in storyboard to dismiss a modally presented tableViewController. When I call the unwindSegue in the didSelectRowAt: override func tableView(_ tableView: ...

Uploading File to server - Swift (uploading contents of file but need complete file to transfer)

I tried with several ways to upload a file from swift to FTP server. All I see is only the contents of the file is transferring and not the complete file. How to transfer the entire file instead of ...

Swift. Xcode. Long subtitle in annotation in MapKit

Hello can you help please? How i can make long subtitle in annotation MapKit? I tried to add label in annotation like that: let detailLabel = UILabel() detailLabel.numberOfLines = 0 detailLabel....

Show a View on First Launch Only - Swift 3

I am implementing a Terms & Conditions view into my app and the user has to accept them to proceed, then when they do accept them, they no longer have to go through the Terms & Conditions view....

Active tableView cells keep getting disabled when I scroll through my tableview

I have app that has a UITableView containing different sections. I want to have only allow access to the first 3 sections i.e the index path 0, 1 and 2. My problem is my code works when the app is ...

calling pcap_loop from Swift 3

I was trying this code from https://github.com/dfrencham/swiftPCap pcap_loop(pcapSession, numberOfPackets, { (args: UnsafeMutablePointer<u_char>, pkthdr:...

asynchronous http request inside a repeat while swift 3

I need to be able to make an asynchronous http request inside a repeat while where the condition is something fed back to me via the response of the web service call. var continueSync = true //let ...

How can I implement MRProgress in Swift 3?

The docs are unclear as to how to implement this beautiful library in Swift I can import MRProgress and get the blurred overlayView to appear but I can't get the progress to update // Attempt one: ...

How to add a UITableView as a subview to a UIView in xib?

I have a custom view that I built using xib file. In this custom view, there is a UIView where I would like to add a static UITableView as a subview. The UITableView to be shown here is present on the ...

Sum the elements of two equal count arrays [duplicate]

I am looking to sum the elements of two equal count arrays "element-by-element" to create a new array. So, let a = [1.0, 2.0, 3.0] let b = [4.0, 5.0, 6.0] I want the following new array c //c = [...

Swift over Objective C to use AVFoundation framework to scan barcodes

I have a project that was developed in objective c. It includes Zbar library to scan barcodes. Im planning to replace Zbar library with build in AVFoundation framework. Now my doubt is, should i write ...

SiriKit: call contact with several numbers

Im make Siri Integration. I have a problem because I don't know how to resolve contacts for contact with two or more numbers. I need something like this: Instead of this Siri offers me to choose ...

UDP BroadcastConnection get response

I created server with PORT:35601, and send a message, everything work well, but i can't get data from server. This is my class class UDPService { fileprivate let connection = ...

Swift 3: Expression type [UIImage] is ambiguous without more context

I try to create new array of UIImage objects: var images = [UIImage](repeating: nil, count: 10) for i in 0..<10 { images[i] = ... } But I got this error (at first row): Expression ...

objc_getClass: load swift class inheriting NSObject

I'm trying to dynamically load a Swift class inheriting from NSObject using the objc runtime. (I'm trying to load the class from ObjC, not from Swift) My Swift class: @objc public class TestClass : ...

Enum element 'default' cannot be referenced as an instance member

I keep getting this error: Enum element 'default' cannot be referenced as an instance member Here is my code: import UIKit class ViewController: UIViewController, UITableViewDelegate, ...

Getting user localisation while application is in the background

I've been working with Xamarin for iOS but realised that Xcode and swift is much better. As a beginner I would like to ask a couple of question for which i was not able to find "best fit" answers. ...

How do I save an integer once in Swift?

Im making a game and when the user collects an orb I want it to save in an lael but only once. I got it to save the integer in a label but need help with not letting the the orb be saved more than ...

openssl include error when compile in new swift project

Hello, I started a new swift project and added files from objc project. I got compiling error at openssl include file. See image. Any suggestions?

Animating the resize of a UIView that has subviews

I've got a UIView that has a UITableView subview. The UIView is a menu, that initially has the width of 50% of the device width, and the UITableView has AutoLayout constraints to the UIView. ...

In Swift 3.0 How to make one character in a string move backward when you typing?

I am new in Swift. I am trying to make a budget application. This app have a Calculator like keyboard. My idea is when users enter the money app will automatically add a decimal place for users. For ...

Push Notifiction and CoreData

i need help, i want save the push notification info in the DB (using core data) when the app is close. I can't get the push notification information when received and the app is close. If the app is ...

Error acessing files in swift 3 [on hold]

first1Sound = Bundle.main.url(forResource: "first1", withExtension: "mp3", subdirectory: "FirstScene/"+GlobalVariables.choicedLanguage)! do{ oneAudio = try AVAudioPlayer(contentsOf: first1Sound,...

How to add more than 4 quick action items in UIApplicationShortcutIcons(3D touch) in iOS Application

I am working on 3D touch features in iOS. I want to add more than 4 shortcut items. I go through apple documentation which states that iOS 9 displays up to four Home screen quick actions for your ...

Compare each element in array in swift

Showing error while comparing for each element in array with index. var dat = ["0","0","1","0","0","0","0","0","0","1","1","0","0","0","0","1","0","0","0","0"] for t in 0...dat.count { if(dat[...

How to make a private function into a helper function?

I have been writing tests for my app. However when running my tests I keep getting the error Stall on main thread on my function private func waitForElementToAppear(testCase: XCTestCase, ...
Translating... 0%