1

I am building an app where I have to pass a specific beacon's accuracy to another view controller but that is leading me to a roadblock.

I have tried passing the accuracy by storing it in a variable but when I pass it on to the new view controller the value just gets fixed to what it detected when it was going to the view controller. For e.g. If the beacon's accuracy at the time it transitioned was 3.00 m the value passed to the other view remains 3.00 m and doesn't change

 @objc func updateCounting(){
        for item in items {
            let beac = item.beacon
            if beac != nil{
                let acc = item.calculateAccuracy(txPower: -70, rssi: Double(beac?.rssi ?? 0))
                let prox = beac?.proximity ?? .unknown
                if acc < 1.50 && prox != .unknown {
                    if let Level2 = self.storyboard!.instantiateViewController(withIdentifier: "ReportVC") as? ReportVC {
                        Level2.passedRes = item.patient
                        Level2.passedRoom = item.room
                        Level2.passResImg = item.resImage
                        Level2.selectedBeacon = beac
                        self.show(Level2, sender: nil)
                        break
                    }
                }
            }else{
                print("No beacon found")
            }

        }
    }

One of the things I tried was passinng the whole beacon to level2 but that didnt work either.

  • Possible duplicate of [Passing Data between View Controllers](https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Aaron Jun 18 '19 at 15:51
  • Making data "available" from `UIViewController` instances others is a pattern issue in iOS. I would highly recommend reading up on MVC https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Model-View-Controller/Model-View-Controller.html – Aaron Jun 18 '19 at 15:52
  • Maybe you need to look at local notifications to keep the value up-to-date in your view controller – Joakim Danielson Jun 18 '19 at 15:52
  • Use `classes` instead of `structs` for your datasource items or setup delegate relationship (same way as `UITableViewDataSource` for example) – Kirow Jun 18 '19 at 15:54
  • @Aaron I get how this maybe a duplicate of that but I am able to pass the static data I need to level2 but not dynamic ( changing ) data from one view controller because when I pass it on, it passes it as a static value. – Saksham Saraswat Jun 18 '19 at 16:10
  • @JoakimDanielson I'll look into that. – Saksham Saraswat Jun 18 '19 at 16:10
  • @Kirow I am using a structs in my model class for items. – Saksham Saraswat Jun 18 '19 at 16:11
  • Have you read the duplicate post that I referenced? – Aaron Jun 18 '19 at 16:12

0 Answers0