Questions tagged [swift]

61610 questions
0

votes
2

answer
22

Views

Perform segue depending on image tapped in TableViews custom cell

Simple as my question on title. I'm trying to go to another view controller depending on the image that someone tap on my table view. Eg: If you tapped on image1 perform segue gotoview1, if you tapped on image2 perform segue gotoview2. I have an array of the images: let gameImages = [UIImage(named:...
Mich1394
0

votes
0

answer
4

Views

Core Data extension to sort entities

The bottom line is to write an extension that sorts an array of NSManagedObjects by dateCreated. Or, to go from this: let materialArray = (Array(quote.materials!) as? [Materials])?.sorted(by: { $0.dateCreated?.compare($1.dateCreated!) == .orderedDescending }) to this: let materialArray = (Array(quot...
squarehippo10
-2

votes
1

answer
38

Views

I have been facing this issue couldn't figure out.its giving me error “Extra argument 'method' in call”

func registerUser(email : String , password: String , completion : @escaping ComplitionHandler) { let lowercaseEmail = email.lowercased() let header = [ "Content-Type": "application/json; charset=utf-8" ] let body : [String: Any] = [ "email" : lowercaseEmail, "password" : password ] AF.request(Regis...
Ahmed Fayyaz
1

votes
1

answer
29

Views

Reusing JSONDecoder or recreating it on every request?

In an asynchronous environment is it more efficient to use one JSONDecoder for all request (Might result in delays if multiple threads are waiting for the lock) or it's more efficient to create a new JSONDecoder for every new request? Apple documentation says that the JSONDecoder class is reusable...
l.vasilev
1

votes
2

answer
340

Views

How to change color of view fade in CATransition

I'm implementing a custom CATransition so I can presentViewController from the left or right instead of the bottom, but am encountering an interesting issue with what the CATransition does. Here is my code: let transition:CATransition = CATransition() transition.duration = 2 transition.timingFuncti...
Unome
1

votes
1

answer
67

Views

Connecting to vimeo video through firebase database issue

I am building an app with several video files. I originally stored them in firebase storage and accessed them through putting their links in firebase data base. On further inspection i think that storing them in fire base my be a bit expensive. so i looked around for alternative options and figured...
pete800
0

votes
1

answer
54

Views

SDK DJI download photo in swift

I am simply attempting to download the latest access the feed from my DJI drone and convert the feed into a UIImage. The easiest way i thought this could be done is take a photo, then promptly afterwards download the latest photo from the storage. I will add the download from storage code below. Is...
Sam
1

votes
1

answer
26

Views

Set a custom font without using attributed text

I don't know what I'm doing wrong, but I'm trying to use plain text in a UILabel using storyboard to have a custom font. I can only see the fonts when I'm switching the text style from Plain text to Attributed. The steps I have done to install them: Dragged fonts into the project (.ttf) Checked tha...
Jacob Ahlberg
0

votes
2

answer
20

Views

How to set flag and pass some values from Popup present model viewcontroller to Tabbar Main Viewcontroller Using Swift 4.2?

My scenario, I am having Tabbar with three viewcontroller. Here, tabbar first viewcontroller I am showing tableview. If I click the tableview cell it will show one popup present model viewcontroller. In this present popup viewcontroller I am maintaining two bar button cancel and done. If I click don...
devmikle
0

votes
3

answer
17

Views

Recursively find a view of a specific type iOS

I have a UIView I want to parse all the subviews of the view and return the instance of subview that is of type CustomClass With view.subviews I only get to immediate subviews , I want to parse all subviews and return my subview that matches a condition. findView(key : uniqueKey , view : UIView) for...
Avinash Sharma
1

votes
1

answer
4.5k

Views

Setting rightBarButtonItem from Navigation Controller

How do you set the right bar button from the navigation controller instead of the view controller? I've been reading about writing SOLID view controller which work only as controllers instead of adding everything to them. The post suggested to move the navigation logic outside the view controller (w...
Lord Zsolt
1

votes
2

answer
2.2k

Views

Function not working in Swift

So I've been trying to learn a bit of Swift and I've been looking at functions with return types. I added this function, and it should work, but I still get the error "Could not find member 'convertFromStringInterpolationSegment.' I've looked at other stack overflow questions and have tried to apply...
Comrod33
1

votes
2

answer
609

Views

How to call a closure passed into a function?

I suspect I am missing something really obviously wrong here, so forgive me if I am being a bit thick. All the examples I see for closures are for passing a closure to the array map function. I want to write my own function which takes a closure This is what I am attempting func closureExample(numb...
rideintothesun
1

votes
1

answer
809

Views

iOS dynamic UI in simple terms?

This may be too basic or require rephrasing. I am in the process of learning Swift and iOS programming and have developed a basic application that runs successfully on my iPhone 5. The app consists of a label, a button, and a UIImageView. It looks the way I want it to on my iPhone 5. I figured most...
bitops
0

votes
1

answer
19

Views

UIPicker View not populating

I'm trying to have 3 picker views populate. For some reason, all of them are showing up blank. Any idea why? import UIKit class ViewController2: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { @IBOutlet weak var seconds: UIPickerView! @IBOutlet weak var minutes: UIPickerView! @IBOut...
Trevor Walker
0

votes
0

answer
9

Views

Can't push or present view controller

This is the function that gets called when a user presses the charge my card button. Charging the card works, but upon pushing the button, the user stays on the same screen. I tried both pushing and presenting but neither worked. Any ideas as to why/how to fix this? @objc private func handleChargeCa...
michaeldebo
0

votes
0

answer
4

Views

Search Firebase data using search bar in Swift

I'm trying to be able to search my Firebase data using a UISearchBar in my app & I am stuck. I am successfully receiving data from Firebase in a table view. I am looking for users to be a to search "releases" by releaseName and/or releaseType. View Firebase data structure View Controller import UIKi...
B. Matlock
0

votes
0

answer
2

Views

How can I detect a change in zoom level in mapbox map?

I am trying to change certain properties of a map and of things on a map when as the user zooms in or out certain distances. How can this be achieved? I have tried: func mapView(_ mapView: MGLMapView, didChange mode: MGLUserTrackingMode, animated: Bool) { print(mode, "This is the mode") print(mapVi...
Outsider
1

votes
1

answer
1.2k

Views

Why is Swift giving me inaccurate floating point arithmetic results? [duplicate]

This question already has an answer here: Is floating point math broken? 28 answers Swift floating point arithmetic seems broken compared to C (and therefore Objective-C). Let's take a simple example. In C: double output = 90/100.0; // Gives 0.9 float output = 90/100.0f; // Gives 0.9 In Swift: var...
Gadzair
1

votes
1

answer
1.1k

Views

Adding KVO to a Settings bundle

I’ve attempted to add KVO to my NSUserDefaults to watch for a value changing in Settings. I’ve added a breakpoint to my observeValueForKeyPath:object:change:context method but it’s never called. Here’s my code: override init() { super.init() NSUserDefaults.standardUserDefaults().addObserver(...
Adam Carter
1

votes
1

answer
185

Views

Swift functions

I am learning Swift and I got problem with understanding how functions work. Let's say I got a simple function: func sayHello() { println("hello there") } And I can assign this function to variable or constant in that way: var hello = sayHello So now variable hello is type of function which can be w...
pardnoj
1

votes
2

answer
12.1k

Views

Dynamically change label when pressing button - iOS Swift

In this there are buttons and when they are pressed I want the label to be changed to that order of operation for example when the Subtraction button is pressed I want the sign to change to a subtraction sign. Here is a picture of the storyboard. https://www.dropbox.com/s/sh61xss16xr2t0t/Screenshot%...
alex
1

votes
3

answer
3.3k

Views

Prototype cells not showing up in UITableView

This is my code: import UIKit class ViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resourc...
1

votes
1

answer
1.1k

Views

How to get the fetchedResultsController.objectAtIndexPath() from within pickerView: titleForRow

I have a UIPickerView and it's datasource is a fetchedResultsController. My delegate func: func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -> String { let task: Task = self.fetchedResultsController.objectAtIndexPath(row) as Task return task.name } resul...
Sam Luther
1

votes
1

answer
5k

Views

Parsing JSON Swift

I am working on an app that displays the live Bitcoin price. I am using 2 APIs to do this - one plaintext, and one JSON. I am having a bit of trouble with the JSON API. Here's a bit of my Swift code func BTCFallback(){ var string2 = currencySelector.currentTitle var url = NSURL(string:"https://bitpa...
rocket101
1

votes
1

answer
569

Views

'@lvalue $T7' is not identical to 'CGPoint!'

I'm attempting to move a collection of nodes in SceneKit on iOS but I'm getting a cryptic error. Here's my code so far: func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) { let cubes = scene.rootNode.childNodesPassingTest { (node, stop) -> Bool in node.name == "cube" } for...
Kyle Decot
1

votes
2

answer
1.5k

Views

Swift Spritekit dissipating Gravity field

I have a game in swift using spritekit. If you tap the screen it will create a radial gravity field and pull all the other objects in. I create the gravity field like so var fieldNode = SKFieldNode.radialGravityField(); fieldNode.falloff = 0.5; fieldNode.strength = 1; fieldNode.animationSpeed = 0.5;...
HarveyBrCo
1

votes
1

answer
677

Views

How do I add a downloaded custom font to a navigationBar title in Swift?

I downloaded a cool font, and want to use it as the nav bar title for my app, but can't seem to get the app to recognize/display it. An exception is thrown every run attempt. Here are the steps I took. I moved the myCustomFont.ttf file into the project as I do other supporting files (images, etc.) U...
Heru
1

votes
1

answer
923

Views

how to count number of sprites swift

I'm building an app that add sprites to the screen. In several parts of my code I want to know how many sprites I have with a certain key. At the moment I implemented it in this way var counter = 0 enumerateChildNodesWithName("box") { node, _ in counter = counter + 1 } println(counter) Is there anot...
Nicholas
1

votes
3

answer
712

Views

Animating UVs in SceneKit

I'm looking for a way to animate sprite sheets in SceneKit. After some research I found the Core Animation way to do this, which would be perfect as I need as much control over the animation as possible. I've prepared a simple plane mesh, with its UVs limited to one spritesheet frame's size. That wa...
sam_vh
1

votes
1

answer
828

Views

Create Loop for Amortization Schedule in Swift

I'm looking to figure out a simple loop in order to calculate an amortization schedule in Swift. So far, here is my setup on Playground: let loanAmount: Double = 250000.00 let intRate: Double = 4.0 let years: Double = 30.0 var r: Double = intRate / 1200 var n: Double = years * 12 var rPower: Double...
ckraider
0

votes
3

answer
27

Views

Tableview cell multiple check mark selection to add cell data into single array Swift 4.2?

My scenario, I have loaded my JSON data into tableView with help of codable. Here, I have added my tableView cell multiple check mark select and deselect. Now, If I am selecting tableView cell I can able to get cell data but I want to add within one array, same if I am unselecting cell It should rem...
devmikle
1

votes
0

answer
13

Views

Sharing CocoaPod using UIApplication.shared between iOS Extension and app

I have a custom built private CocoaPod that I wrote. I'm trying to use it in my iOS application, which is working fine. But when I add it to my iMessage App or Share Extension it fails and gives me an error 'shared' is unavailable: Use view controller based solutions where appropriate instead. when...
Charlie Fish
1

votes
1

answer
1.9k

Views

Swift AVPlayer to ear speaker

I've got a simple audio player that works great. I'm playing a remote URL MP3. My code: @IBAction func playAudio(sender: AnyObject) { let url = self.productAudio let playerItem = AVPlayerItem( URL:NSURL( string:url ) ) player = AVPlayer(playerItem:playerItem) player. player.rate = 1.0; player.play()...
pekpon
1

votes
1

answer
4.1k

Views

Call function in view controller from UITableViewCell

I have a problem which drives me nuts, how is it possible to invoke a function in a view controller from within a UITableViewCell. - I am doing that in Swift. So I have a View Controller - called mainVC in this mainVC I have declared a tableView which holds a UITableViewCell (Custom/ Dynamic) in tha...
Armin Scheithauer
1

votes
3

answer
468

Views

How to prevent class instance from being modified?

Question: Is there a way to prevent a class instance (reference type) from being modified ? Reason: The reason for asking this is because when a reference to a class instance is passed to a function, the function might unintentionally modify the instance. Note: Using let or private function / prope...
user1046037
1

votes
3

answer
1k

Views

Handle unknown content-type of response with Alamofire

I use Alamofire to do requests to a rest service. If the request is successful the server returns a JSON with content-type application/json. But if the request fails the server returns a simple String. So, I don't know how to handle on it with Alamofire, because I don't know how the response look li...
Karl
1

votes
2

answer
2.8k

Views

'Cannot convert the expression's type' with optional in closure body

I have come across (most definitely) a feature that I don't quite understand. I have a closure, that takes in a Float and has no return value, aka (number: Float) -> Void. In that closure, I perform a call on optional value, not forcing its unwrapping, because I like the behavior since the optional...
Michal
1

votes
2

answer
1.9k

Views

anyobject does not have a membered named objectforkey in SWIFT

I am trying to get the objectForKey from a notifaction, although I am getting the error: anyobject does not have a membered named objectforkey The code I am using is: func executeAlbum(notification:NSNotification){ let data = notification.userInfo.objectForKey("data") as [AlbumModel] // ERROR HERE s...
Henry Brown
1

votes
3

answer
1.8k

Views

Swift: Check which value in NSArray is closest to another given value

Lets say I have an array var values:[CGFloat] = [-12.0, 450, 300] I need to find out which of these numbers is closest to a given value, say var givenValue:CGFloat = 64 Is there an efficient way to find out which object in the array is closest to 64? I know you can do something like this: if abs(va...
George Poulos

View additional questions