swift3

Convert optional string to double in Swift 3

↘锁芯ラ 提交于 2019-12-23 06:57:29
问题 I have a option string and want to convert that to double. this worked in Swift 2 , but since converted to Swift 3, I am getting value of 0. var dLati = 0.0 dLati = (latitude as NSString).doubleValue I have check and latitude has a optional string value of something like -80.234543218675654 , but dLati value is 0 *************** ok, new update for clarity ***************** I have a viewcontroller which i have a button in it, and when the button is touched, it will call another viewcontroller

Swift Access Constraint from different View controller found nil

限于喜欢 提交于 2019-12-23 06:29:10
问题 Hello I'm trying to access my constraint from my second view controller to my initial view controller, but it always give an error, Im accessing my constraint from a pageviewontroller class, to automatically adjust the height of my second page. found nil while unwrapping optional value func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { guard let viewControllerIndex = orderedViewControllers.index(of:

Does a parent have its children's physicsBodies?

隐身守侯 提交于 2019-12-23 06:20:48
问题 I was wondering what the physicsBody of a parent would be if all I do is this: let combinedBodies = SKSpriteNode() addChild(combinedBodies) //Create its children like this as an example: let child = SKSpriteNode(color: UIColor.red, size: CGSize(width: 10, height: 20)) child.physicsBody = SKPhysicsBody(rectangleOf: child.size) child.physicsBody?.categoryBitMask = collisionType.child.rawValue combinedBodies.addChild(child) allBodies.append(child.physicsBody?) Would the physicsBody of

Trying to draw dashed border for UITableViewCell

馋奶兔 提交于 2019-12-23 06:13:08
问题 I'm trying to draw a dashed bottom border to UITableViewCells with the following code: func addDashedBottomBorder(to cell: UITableViewCell) { let width = CGFloat(2.0) let dashedBorderLayer: CAShapeLayer = CAShapeLayer() let frameSize = cell.frame.size let shapeRect = CGRect(x: 0, y: frameSize.height, width: frameSize.width*2, height: 1) dashedBorderLayer.bounds = shapeRect dashedBorderLayer.position = CGPoint(x: 0, y: frameSize.height) dashedBorderLayer.strokeColor = UIColor.lightGray.cgColor

Image path not convert to url in swift3

大城市里の小女人 提交于 2019-12-23 06:09:33
问题 I have post response i want to download image from image_path let fileUrl = NSURL(fileURLWithPath: (posts.value(forKey: "image_path") as! [String])[indexPath.row]) print(fileUrl as Any) // here i can get path if FileManager.default.fileExists(atPath: (fileUrl)// nil value { let url = NSURL(string: (posts.value(forKey: "image_path") as! [String])[indexPath.row]) // Here url found nil let data = NSData(contentsOf: url! as URL) cell.LocationImage?.image = UIImage(data: data! as Data) } UPDATE:

Get actual coordinate of pdf in Webview when touch with Swift 3

亡梦爱人 提交于 2019-12-23 05:42:10
问题 I have successfully to load a pdf file from URL to a web view. I want to get the coordinates after touch on webview to sent it data to server to add some text to that position in server side. Problem is how can I get that coordinates when webview is zooming or scroll to page 2,3.. Could you please help me to solve the problem in Swift 3 Here the code class ViewController: UIViewController, UITextFieldDelegate, UIGestureRecognizerDelegate, UIWebViewDelegate { @IBOutlet var imageView:

How to make auto numbering on UITextview when press return key in swift

馋奶兔 提交于 2019-12-23 05:35:12
问题 When user press [Return] key then need to display the number. Like serial numbers [1,2 etc] for each line.Is there any way to do that? Following code I tried func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { var textview_text_nssring = textView.text as NSString // Add "1" when the user starts typing into the text field if (range.location == 0 && textView.text.isEmpty ) { if text == "\n" { textView.text = "1." let cursor =

Collectionview in tableview cell

倾然丶 夕夏残阳落幕 提交于 2019-12-23 05:34:15
问题 I have taken collection view in tableview cell now when I click the collection view cell it will go to the next view controller,is it possible? I have tried did select item method in that how to use perform segue method 回答1: I am showing u example class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool { return false } } This

Dynamic cell height for textView Swift

那年仲夏 提交于 2019-12-23 05:10:33
问题 I was using a label before and it was working fine. But I just realized I need a UITextView instead and I cant seem to get it working right. The text just keeps going to the right and I can no longer see it. I need it to adjust to the dynamic height of the cell liked it worked before with the label. struct postStruct { let username : String! let message : String! let photoURL : String! let timeStamp: String! let cellUserId : String! } class GeneralChatroom: UIViewController,

AVAudioplayer: Volume drops after couple of seconds

江枫思渺然 提交于 2019-12-23 05:10:16
问题 I've implemented an audioplayer on iOS 10.2.1 with XCode Version 8.2.1 (8C1002) on Mac OS Sierra 10.12.3 When the song starts playing the volume drops quite a bit after a couple of seconds. Has anyone experienced such an effect? do { myAudioPlayer = try AVAudioPlayer(contentsOf: url!) myAudioPlayer.prepareToPlay() myAudioPlayer.volume = 1.0 } catch { print(error) } 来源: https://stackoverflow.com/questions/43076669/avaudioplayer-volume-drops-after-couple-of-seconds