#StackBounty: #swift #scenekit #augmented-reality #arkit #hittest Place multiple SCN objects in touchesBegan method

Bounty: 50

My Swift code below uses func touchesBegan to place a SCN object in the ARKit view. The problem is – it’s only placing the object one time. I would like to create the code in a way that users can select any area to place the SCN object and it can place it as many times as they want too.

Here’s GitHub link.

enter image description here

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {  
        // Handle the shooting
        guard let frame = sceneView.session.currentFrame else { return }
        let camMatrix = SCNMatrix4(frame.camera.transform)
        let direction = SCNVector3Make(-camMatrix.m31 * 5.0, -camMatrix.m32 * 10.0, -camMatrix.m33 * 5.0)
        let position = SCNVector3Make(camMatrix.m41, camMatrix.m42, camMatrix.m43)
        let scene = SCNScene(named: "art.scnassets/dontCare.scn")!
        sceneView.scene = scene

Get this bounty!!!

#StackBounty: #framework #user-interface #macos #swift What is the best alternative to SwiftUI for MacOS?

Bounty: 100

SwiftUI seems to have good features, but only works on MacOS 1.15 and newer. Is there a framework for MacOS that is efficient, and shares the capabilities of SwiftUI. Well technically, if I put everything in the draw() method of an NSView, it can in theory replicate all of the functionallity. However, it will be very difficult to replicate animating transitions. Another thing is, for some reason, drawing a single round-cornered rectange, like this:

    NSColor(red: 0.5, green: 1, blue: 1, alpha: 1).set()
    let Shape = NSBezierPath()
    let ActualY = (dirtyRect.height/2)
    let FarXOrigin = dirtyRect.width*0.75, CornerRadius = dirtyRect.width/96, Height = dirtyRect.width/20, CloseXOrigin = dirtyRect.width/4, ControlPointOffset = CornerRadius*0.552284749831, Y = ActualY+(Height/4)+CornerRadius
    Shape.move(to: NSMakePoint(FarXOrigin-CornerRadius, CGFloat(Y)))
    Shape.curve(to: NSMakePoint(FarXOrigin, CGFloat(Y)-CornerRadius), controlPoint1: NSMakePoint(FarXOrigin-CornerRadius+ControlPointOffset, CGFloat(Y)), controlPoint2: NSMakePoint(FarXOrigin, CGFloat(Y)-CornerRadius+ControlPointOffset))
    Shape.line(to: NSMakePoint(FarXOrigin, CGFloat(Y)-(CornerRadius+Height-(CornerRadius*2))))
    Shape.curve(to: NSMakePoint(FarXOrigin-CornerRadius, CGFloat(Y)-Height), controlPoint1: NSMakePoint(FarXOrigin, CGFloat(Y)-(CornerRadius+Height-(CornerRadius*2)+ControlPointOffset)), controlPoint2: NSMakePoint(FarXOrigin-CornerRadius+ControlPointOffset, CGFloat(Y)-Height))
    Shape.line(to: NSMakePoint(CloseXOrigin+CornerRadius, CGFloat(Y)-Height))
    Shape.curve(to: NSMakePoint(CloseXOrigin, CGFloat(Y)-(CornerRadius+Height-(CornerRadius*2))), controlPoint1: NSMakePoint(CloseXOrigin+CornerRadius-ControlPointOffset, CGFloat(Y)-Height), controlPoint2: NSMakePoint(CloseXOrigin, CGFloat(Y)-(CornerRadius+Height-(CornerRadius*2)+ControlPointOffset)))
    Shape.line(to: NSMakePoint(CloseXOrigin, CGFloat(Y)-CornerRadius))
    Shape.curve(to: NSMakePoint(CloseXOrigin+CornerRadius, CGFloat(Y)), controlPoint1: NSMakePoint(CloseXOrigin, CGFloat(Y)-CornerRadius+ControlPointOffset), controlPoint2: NSMakePoint(CloseXOrigin+CornerRadius-ControlPointOffset, CGFloat(Y)))

takes up a LOT more memory than calling RoundedRectangle() MULTIPLE times in SwiftUI. Also the edges in the SwiftUI round rectangle look sharp, and when drawing in an NSView, the edges look slightly less well defined. I want a backwards-compatible framework that can do custom drawing EFFICIENTLY, and that I do not have to recreate too many features. What should I do? How would I create a very lightweight user interface with all the features that SwiftUI can do?

Get this bounty!!!

#StackBounty: #ios #swift #delegates #segue #protocols Protocol delegate between view before navigation stack

Bounty: 50

View1 segues to Navigation ControllerView2 segues to View3

I am trying to create protocol delegate from View3 to View1

In View1

class NormalUser: UIViewController, NormalUserDelegate {

   @objc func showAddressView() {

        addressView.isHidden = false

override func viewDidLoad() {

        if let conn = self.storyboard?.instantiateViewController(withIdentifier: "View") as? View
          conn.delegate = self

In View3

weak var delegate: NormalUserDelegate?

func test() {




protocol NormalUserDelegate: class {
    func showAddressView()

I couldn’t make it work. Any idea?

Get this bounty!!!

#StackBounty: #ios #swift #avplayer #vimeo AVPlayer videos not loading all the time

Bounty: 250

My app uses AVPlayer to play my videos however they do not play every time. I just get a black screen on some videos. However the videos that don’t play aren’t the same every time. I don’t understand why one minute it works and then the next it doesn’t. I am using the HCVimeoVideoExtractor in order to pull the videos from Vimeo.

 import UIKit
 import HCVimeoVideoExtractor
 import Foundation
 import AVKit
 import AVFoundation

 class Arms : UITableViewController{

@IBOutlet var Tableview: UITableView!

//video outlet
let playerController = AVPlayerViewController()

//@IBOutlet var mypic: UIImageView!

let sectionName = ["Day 0","Day 1","Day 2","Day 3","Day 4","Day 5","Day 6","7"]

     let foodTitleArray = ["1 and a Half Cable Bicep Curl", "Barbell Bicep Curls", "Cable Bicep Curl","Dumbbell Bicep Curl","Bench Press Close Grip","Across The Body Tricep Extension","EZ Bar Curl", "Dumbbell Hammer Curl", "Low Pulley Cable Curl", "Preacher Curl Machine", "Skull Crusher", "Straight Bar Tricep Extension", "Rope Tricep Extension"]

let foodImageArray = ["Bicep Curl 1 and half Cable", "Bicep Curl Barbell", "Bicep Curl Cable","Bicep Curl Dumbbell","Close Grip Bench Press","Cross body tricep extension","EZ Bar Curl", "Hammer Curl Dumbbell", "Low Cable Pulley Curl", "Preacher Curl Machine", "Skull Crusher", "Tricep extension Cable", "Tricep Extension rope"]

var rowselected = Int()

//video links
var calledVideo: String?

let vids = ["https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345","https://vimeo.com/12345", "https://vimeo.com/12345", "https://vimeo.com/12345", "https://vimeo.com/12345"]

override func viewDidLoad() {

    @IBAction func Back(_ sender: Any) {


    self.dismiss(animated: true, completion: nil)

//setting up tableview rows
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //return sectionName.count
    return foodTitleArray.count

//what cell is & how it looks
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = Tableview.dequeueReusableCell(withIdentifier: "cellarms") as! UITableViewCell1

    // cell.foodImage.image = UIImage(named: foodImageArray[indexPath.row] + ".jpg") //this is origionally how memory images are used added to cell. this way caches the images building memory.
     cell.foodTitle.text = foodTitleArray[indexPath.row] //this is how to the uitableviews titles are added to cells

    //shows the images in cells without storing image in cache
    let bundlePath = Bundle.main.path(forResource: foodImageArray[indexPath.row], ofType: "jpg")
    let image = UIImage(contentsOfFile: bundlePath!)
    cell.foodImage.image = image

    return (cell)

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    rowselected = indexPath.row

   //indexpath.row is the code to get a number of the row selected this number then is selected from vids array and sets calledvideo to this number.
    let number = indexPath.row
    calledVideo = vids[number]

    //making desleected row not highlighted
    tableView.deselectRow(at: indexPath, animated: true)


    //Getting url info for video by using exractor
    func geturl() {
    if let url = URL(string: calledVideo!) {
        HCVimeoVideoExtractor.fetchVideoURLFrom(url: url, completion: { ( video:HCVimeoVideo?, error:Error?) -> Void in

            if let err = error {
                DispatchQueue.main.async() {
                    let alert = UIAlertController(title: "Error", message: err.localizedDescription, preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                    self.present(alert, animated: true, completion: nil)

            guard let vid = video else {
                print("Invalid video object")

            //play video
            let player = AVPlayer(url: vid.videoURL[.Quality360p]!)
            self.playerController.player = player
            self.present(self.playerController, animated: true) {




Get this bounty!!!

#StackBounty: #swift #swiftui Handling derived state in SwiftUI

Bounty: 50

say I am creating an “Date Editor” view. The goal is:
– Take a default, seed date.
– It lets the user alter the input.
– If the user then chooses, they can press “Save”, in which case the owner of the view can decide to do something with the data.

Here’s one way to implement it:

struct AlarmEditor : View {
    var seedDate : Date
    var handleSave : (Date) -> Void

    @State var editingDate : Date?

    var body : some View {
        let dateBinding : Binding<Date> = Binding(
            get: {
                return self.editingDate ?? seedDate
            set: { date in
                self.editingDate = date

        return VStack {
                selection: dateBinding,
                displayedComponents: .hourAndMinute,
                label: { Text("Date") }
            Button(action: {
            }) {

The Problem

What if the owner changes the value of seedDate?

Say in that case, what I wanted to do was to reset the value of editingDate to the new seedDate.

What would be an idiomatic way of doing this?

Get this bounty!!!

#StackBounty: #swift #uitableview #uicollectionview #uicollectionviewcell #uicollectionviewlayout align single UICollectionViewCell to …

Bounty: 50

I’ve got a collectionView that is inside a tableView cell. The collectionView has multiple sections. If a section has only one cell, the cell appears centered. How can I align that single cell to the left?

collectionView inside tableView cell

The collectionView has the following flowLayout:

let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .vertical
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
flowLayout.minimumInteritemSpacing = 0
flowLayout.minimumLineSpacing = 0
flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
collectionView.setCollectionViewLayout(flowLayout, animated: true)

Get this bounty!!!

#StackBounty: #ios #swift #swift4 #swift5 Navigation bar appear on click on view

Bounty: 50

I attach the video of my issue. When i click on anywhere in viewcontroller navigation bar is appear

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(true, animated: true)
    self.navigationController?.isNavigationBarHidden = true
    self.navigationController?.hidesBarsOnTap = true

The above code added on viewwillappear its working on initially but when I click anywhere on screen navigationbar is appear.

Get this bounty!!!

#StackBounty: #swift #ios #search Searching within a data model using an array matching multiple terms

Bounty: 50

I have a standard tableview app that displays information from a data model array that uses a custom class. There is a UISearchController to filter the data.

A simplified version of the custom class is shown. I use a computed property for a string that is checked when searching the data.

class myObject: NSObject {

    // Inherits from NSObject as I use NSCoding for persistence

    var id: String = UUID().uuidString // These are unique for each item

    var name: String = ""
    var type: String = ""
    var batch: String = ""

    var searchableString: String {
        // This is a concatenation of some of the properties
        return self.name + " " + self.type + " " + self.batch

    // etc...

Every time the user types a new character into the search bar of the UISearchController, the following method is called, which filters the main data array into a filteredItems array. Initially, I used a very basic form where the entire search text had to match.

func searchItems() {
    if let searchText = searchController.searchBar.text {
        filteredItems = allItems.filter { item in
            return item.searchableString.lowercased().contains(searchText.lowercased())

filteredItems is then displayed in the tableview.

I wanted to improve this so that each word typed in the search bar is searched for separately. I tried this, but of course it filters using OR logic (any word can match).

func searchItems() {
    if let searchText = searchController.searchBar.text?.split(separator: " ") {
        // Need to convert substring from split back to string
        let searchArray = searchText.map() { substring in
        filteredItems = allItems.filter { item in
            return searchArray.contains(where: drug.searchableString.lowercased().contains)

In order to get the desired AND logic (every word typed must match), I had to use this.

func searchItems() {
    if let searchText = searchController.searchBar.text?.split(separator: " ") {
        // Need to convert substring from split back to string
        let searchArray = searchText.map() { substring in
        filteredItems = allItems.filter { item in
            for word in searchArray {
                if !item.searchableString.lowercased().contains(word) {
                    return false
            return true

This works as intended, but it does not seem elegant. Is there a better way to filter the array allItems to filteredItems based on matching text in those String properties of the objects in my data model?

Get this bounty!!!

#StackBounty: #ios #swift #statusbar #ios13 preferredStatusBarStyle not getting called in iOS 13 and other

Bounty: 50

I have multiple UITabBar in my application and some ViewController has White color statusbar and some ViewController has black color statusbar.

My info.plist

View controller-based status bar appearance to YES

My Viewcontroller has below code.

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .default //or return . lightContent

but preferredStatusBarStyle never getting called.

i have also written below line in my controller viewDidLoad but still above wasn’t getting called.


also i have changeed controller-based status bar appearance to YES && NO for multiple time to check but nothing helps to me.

I have also tried below solutions and other stackoverflow answers but nothing helps me.

preferredStatusBarStyle not respecting on iOS 13

preferredStatusBarStyle var not working in iOS12?


I have tried below code which returns me the topViewController and it will call the preferredStatusBarStyle of that ViewController

extension UINavigationController {
    override open var childForStatusBarStyle: UIViewController? {
        return topViewController

so once the topViewController found it will call preferredStatusBarStyle of that particular ViewController.

but the issue is that it wasn’t getting called inside UITabBarController -> UINavigationController -> UIViewController.


I have 2 different TabBarController.

1st TabBarController statusBarStyle is .lightContent.

2nd TabBarController statusBarStyle is .lightContent and .default in different controller.

When i change to the 2nd TabBarController it will call preferredStatusBarStyle of 2nd TabBarController and all ViewController statusBarStyle goes .default but some of my controller statusBarStyle wants to be of .ligthContent

How can i achieve this?

any help will be appreciated.


Get this bounty!!!

#StackBounty: #ios #objective-c #swift #xcode #camera iphone image captured from camera rotate automatically Swift

Bounty: 50

Programmatically, I have captured image from my camera in my app. It has been fetched nicely, but when I shift to another, view and dismiss that view at that time my image I want to rotate into landscape. I captured images from camera. When I fetch image from photo library no issue has been found.

Following image is my original image.
Screen Shot

And I want to rotate image.
Screen Shot

Code Below:

var captureSesssion : AVCaptureSession!
var cameraOutput : AVCapturePhotoOutput!
var previewLayer : AVCaptureVideoPreviewLayer!
var device:AVCaptureDevice!
var currentViewControl = UIViewController()
var tempImageHolder = UIImage()

func beginCamera(_ targetView: UIView, _ currentVC: UIViewController) 
    currentViewControl = currentVC
    // Do any additional setup after loading the view, typically from a nib.
    captureSesssion = AVCaptureSession()
    captureSesssion.sessionPreset = AVCaptureSession.Preset.photo
    cameraOutput = AVCapturePhotoOutput()

    if #available(iOS 11.1, *) {
        let availableDevices = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera, .builtInTelephotoCamera, .builtInTrueDepthCamera], mediaType: AVMediaType.video, position: .back).devices
        device = availableDevices.first
    } else {
        // Fallback on earlier versions
        device = AVCaptureDevice.default(for: .video)!

    if let input = try? AVCaptureDeviceInput(device: device!) {
        if (captureSesssion.canAddInput(input)) {
            if (captureSesssion.canAddOutput(cameraOutput)) {
                let connection = cameraOutput.connection(with: AVFoundation.AVMediaType.video)
                connection?.videoOrientation = .portrait
                previewLayer = AVCaptureVideoPreviewLayer(session: captureSesssion)
                self.previewLayer.frame = targetView.frame
                self.previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
        } else {
            print("issue here : captureSesssion.canAddInput")
    } else {
        print("some problem here")
    previewLayer?.frame.size = targetView.frame.size

   func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
    if let error = error {
        // we got back an error!
        let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default))
        currentViewControl.present(alert, animated: true)
    } else {

 func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
    let imageData = photo.fileDataRepresentation()
    let imageSize: Int = imageData!.count
    tempImageHolder = UIImage(data: (imageData! as NSData) as Data)!
    //When use this below line works fine when take images from left landscape, but when take images from right landscape image not show properly screen shot below:
    tempImageHolder = UIImage(cgImage: tempImageHolder.cgImage!, scale: tempImageHolder.scale, orientation: .up)

When take images from left landscape:

Input: Screen Shot

Output: Screen Shot

When take images from right landscape

Input: Screen Shot

Output: Screen Shot

UIImage(cgImage: tempImageHolder.cgImage!, scale: tempImageHolder.scale, orientation: .up)

When use this above line works fine when take images from left landscape, but when take images from right landscape image not show properly screen shot

Can someone please explain to me how to rotate image. Any help would be greatly appreciated.

Thanks in advance.

Get this bounty!!!