[Solved] How I getting array data in Swift? [closed]

You need to be more precise when you write code. Your array of integers has a different number than the example output you want. I thought perhaps you wanted a set for a response, but there were two fails in there, so I ruled that out, too. Another source of imprecision are the ranges you … Read more

[Solved] Swift 4 days until date [duplicate]

It would be helpful to see what you’ve tried to give some advice, but nonetheless, you can use NSCalendar’s components to accomplish this. let calendar = Calendar.current let startOfDay1 = calendar.startOfDay(for: date1) let startOfDay2 = calendar.startOfDay(for: date2) let components = calendar.dateComponents([.day], from: startOfDay1, to: startOfDay2) You can customize that above to get more specific minutes … Read more

[Solved] NSUserDefaults for high score is not working on iOS 8 Simulator?

Let’s step through your code. First, you overwrite whatever the high score was with 0: //To save highest score let highscore = 0 let userDefaults = NSUserDefaults.standardUserDefaults() NSUserDefaults.standardUserDefaults().setObject(highscore, forKey: “highscore”) NSUserDefaults.standardUserDefaults().synchronize() Then, you’re checking if “highscore” is in the defaults: if let highscore: AnyObject = userDefaults.valueForKey(“highscore”) { A few notes: This will always be true … Read more

[Solved] How can you add padding between views in a UIScrollView in Swift? [closed]

Your constraints are likely not behaving like you expect. My strong suggestion is to use a UIStackView instead, and bind it to the scroll view via constraints, but not your images. let stackView = UIStackView() stackView.axis = .vertical stackView.spacing = 8 // or whatever you want stackView.addArrangedSubview(image1) stackView.addArrangedSubview(image2) scrollView.addSubview(stackView) stackView.translatesAutoresizingMask = false // finish the … Read more

[Solved] Basic Swift grammar

Your code does not compile. sender is Any, so you can’t access the property titleLabel directly. You either have to write: guard let senderedText = (sender as? UIButton)?.titleLabel?.text else { return } Or change the parameter type: @IBAction func inputformula(_ sender: UIButton) { As you can see, I inferred sender to be a UIButton because … Read more

[Solved] A closed range can never be empty, Why?

A Closed Range contains both its lower bound and its upper bound. So even if you wrote: let someRange = 0…0 It still contains one element: 0. How would you attempt write an empty range? let someRange = … ?? That doesn’t make much sense, and if you specify either the upper or lower bound, … Read more

[Solved] How to tell if a video is HDR or not in Swift?

Simple and precise: var isHdrVideo = false let pVideoTrack = AVAsset(url: URL(fileURLWithPath: assetURL!)) if #available(iOS 14.0, *) { let tracks = pVideoTrack.tracks(withMediaCharacteristic: .containsHDRVideo) for track in tracks{ isHdrVideo = track.hasMediaCharacteristic(.containsHDRVideo) if(isHdrVideo){ break } } } solved How to tell if a video is HDR or not in Swift?