【问题标题】:can't get returned values in a structure in swift 3在swift 3中无法在结构中获取返回值
【发布时间】:2017-12-04 20:22:33
【问题描述】:

我有这个代码:

//
//  Measurement.swift
//  BicycleSpeed

    import Foundation
    import CoreBluetooth

    // CSC Measurement
    // https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.csc_measurement.xml
    //
    //  Flags : 1 byte.  Bit 0: Wheel. Bit 1: Crank
    //  Cumulative Wheel revolutions: 4 bytes uint32
    //  Last wheel event time: 2 bytes. uint16 (1/1024s)
    //  Cumulative Crank revolutions: 2 bytes uint16
    //  Last cranck event time: 2 bytes. uint16 (1/1024s)


    struct Measurement : CustomDebugStringConvertible {

      let hasWheel:Bool
      let hasCrank:Bool
      let cumulativeWheel:UInt32
      let lastWheelEventTime:TimeInterval
      let cumulativeCrank:UInt16
      let lastCrankEventTime:TimeInterval
      let wheelSize:UInt32


      init(data:Data, wheelSize:UInt32) {

        self.wheelSize = wheelSize
        // Flags
        var flags:UInt8=0
        (data as NSData).getBytes(&flags, range: NSRange(location: 0, length: 1))

        hasWheel = ((flags & BTConstants.WheelFlagMask) > 0)
        hasCrank = ((flags & BTConstants.CrankFlagMask) > 0)

        var wheel:UInt32=0
        var wheelTime:UInt16=0
        var crank:UInt16=0
        var crankTime:UInt16=0

        var currentOffset = 1
        var length = 0

        if ( hasWheel ) {

          length = MemoryLayout<UInt32>.size
          (data as NSData).getBytes(&wheel, range: NSRange(location: currentOffset, length: length))
          currentOffset += length

          length = MemoryLayout<UInt16>.size
          (data as NSData).getBytes(&wheelTime, range: NSRange(location: currentOffset, length: length))
          currentOffset += length
        }

        if ( hasCrank ) {

          length = MemoryLayout<UInt16>.size
          (data as NSData).getBytes(&crank, range: NSRange(location: currentOffset, length: length))
          currentOffset += length

          length = MemoryLayout<UInt16>.size
          (data as NSData).getBytes(&crankTime, range: NSRange(location: currentOffset, length: length))
          currentOffset += length
        }

        cumulativeWheel     = CFSwapInt32LittleToHost(wheel)
        lastWheelEventTime  = TimeInterval( Double(CFSwapInt16LittleToHost(wheelTime))/BTConstants.TimeScale)
        cumulativeCrank     = CFSwapInt16LittleToHost(crank)
        lastCrankEventTime  = TimeInterval( Double(CFSwapInt16LittleToHost(crankTime))/BTConstants.TimeScale)

      }

      func timeIntervalForCurrentSample( _ current:TimeInterval, previous:TimeInterval ) -> TimeInterval {
        var timeDiff:TimeInterval = 0
        if( current >= previous ) {
            timeDiff = current - previous
        }
        else {
          // passed the maximum value
          timeDiff =  ( TimeInterval((Double( UINT16_MAX) / BTConstants.TimeScale)) - previous) + current
        }
        return timeDiff

      }

      func valueDiffForCurrentSample<T:UnsignedInteger>( _ current:T, previous:T , max:T) -> T {

        var diff:T = 0
        if  ( current >= previous ) {
          diff = current - previous
        }
        else {
           diff = ( max - previous ) + current
        }
        return diff
      }


      func valuesForPreviousMeasurement( _ previousSample:Measurement? ) -> ( cadenceinRPM:Double?, distanceinMeters:Double?, speedInMetersPerSecond:Double?)? {


        var distance:Double?, cadence:Double?, speed:Double?
        guard let previousSample = previousSample else {
          return nil
        }
        if ( hasWheel && previousSample.hasWheel ) {
          let wheelTimeDiff = timeIntervalForCurrentSample(lastWheelEventTime, previous: previousSample.lastWheelEventTime)
          let valueDiff = valueDiffForCurrentSample(cumulativeWheel, previous: previousSample.cumulativeWheel, max: UInt32.max)

          distance = Double( valueDiff * wheelSize) / 1000.0 // distance in meters
          if  distance != nil  &&  wheelTimeDiff > 0 {
            speed = (wheelTimeDiff == 0 ) ? 0 : distance! / wheelTimeDiff // m/s
          }
        }

        if( hasCrank && previousSample.hasCrank ) {
          let crankDiffTime = timeIntervalForCurrentSample(lastCrankEventTime, previous: previousSample.lastCrankEventTime)
          let valueDiff = Double(valueDiffForCurrentSample(cumulativeCrank, previous: previousSample.cumulativeCrank, max: UInt16.max))

          cadence = (crankDiffTime == 0) ? 0 : Double(60.0 * valueDiff / crankDiffTime) // RPM

        }
        print( "Cadence: \(String(describing: cadence)) RPM. Distance: \(String(describing: distance)) meters. Speed: \(String(describing: speed)) Km/h" )
        return ( cadenceinRPM:cadence, distanceinMeters:distance, speedInMetersPerSecond:speed)



      }

      var debugDescription:String {
        get {
            return "Wheel Revs: \(cumulativeWheel). Last wheel event time: \(lastWheelEventTime). Crank Revs: \(cumulativeCrank). Last Crank event time: \(lastCrankEventTime)"
        }
      }

        var myMeasurement = ((Measurement?) -> (cadenceinRPM: Double?, DistanceinMeters: Double?, speedinMetersPerSecond: Double?)).self


        struct dataVariables {

            static var mySpeed = myMeasurement.speedInMetersPerSecond


            static var myCadence : Double?
            static var miDistance : Double?

            static var myLastWheelEventTime : Double? = Measurement.valuesForPreviousMeasurement(lastWheelEventTime)

            static var myLastCrankEventTime : Double? = Measurement.valuesForPreviousMeasurement(lastCrankEventTime)


        }
    }


    }

我正在尝试将返回值 cadenceinRPM、distanceinMeters、speedinMetersPerSecond 分配给 struct dataVariables 中的静态变量
以及 lastWheelEventTime 和 lastCrankEventTime,所以我可以在另一个类中访问它们,但是我遇到了以下错误: 在 var mySpeed 上:实例成员“myMeasurement”不能用于“Measurement”类型 在 var myLastWheelEventTime 和 var myLastCrankEventTime 上:实例成员“valuesForPreviousMeasurement”不能用于“Measurement”类型;你的意思是使用这种类型的值吗? 怎么能比那些返回值的引用呢? 有人可以解释错误吗?我搜索了其他类似的问题,但我还没有找到解决方案 我试图将 var myVariable 更改为

var myMeasurement = Measurement.self

但错误保持不变。

还有其他代码

    //
//  CadenceSensor.swift

import Foundation
import CoreBluetooth

/*
 // Bluetooth  "Cycling Speed and Cadence"
 https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.cycling_speed_and_cadence.xml

 Service Cycling Speed and Cadence. Characteristic [2A5B]  // Measurement
 Service Cycling Speed and Cadence. Characteristic [2A5C]  // Supported Features
 Service Cycling Speed and Cadence. Characteristic [2A5D]  // Sensor location
 Service Cycling Speed and Cadence. Characteristic [2A55]  // Control Point

 */

public struct BTConstants {
    static let CadenceService         = "1816"
    static let CSCMeasurementUUID     = "2a5b"
    static let CSCFeatureUUID         = "2a5c"
    static let SensorLocationUUID     = "2a5d"
    static let ControlPointUUID       = "2a55"
    static let WheelFlagMask:UInt8    = 0b01
    static let CrankFlagMask:UInt8    = 0b10
    static let DefaultWheelSize:UInt32   = UInt32(myVariables.circonferenzaRuota!)  // In millimiters. 700x30 (by default my bike's wheels) :)
    static let TimeScale              = 1024.0
}

protocol CadenceSensorDelegate {

    func errorDiscoveringSensorInformation(_ error:NSError)
    func sensorReady()
    func sensorUpdatedValues( speedInMetersPerSecond speed:Double?, cadenceInRpm cadence:Double?, distanceInMeters distance:Double? )
}

class CadenceSensor: NSObject {

    let peripheral:CBPeripheral
    var sensorDelegate:CadenceSensorDelegate?
    var measurementCharasteristic:CBCharacteristic?
    var lastMeasurement:Measurement?
    let wheelCircunference:UInt32


    init(peripheral:CBPeripheral , wheel:UInt32=BTConstants.DefaultWheelSize) {
        self.peripheral = peripheral
        wheelCircunference = wheel
    }

    func start() {
        self.peripheral.discoverServices(nil)
        self.peripheral.delegate = self
    }


    func stop() {
        if let measurementCharasteristic = measurementCharasteristic {
            peripheral.setNotifyValue(false, for: measurementCharasteristic)
        }

    }

    func handleValueData( _ data:Data ) {

        let measurement = Measurement(data: data, wheelSize: wheelCircunference)
        print("\(measurement)")

        let values = measurement.valuesForPreviousMeasurement(lastMeasurement)
        lastMeasurement = measurement

        sensorDelegate?.sensorUpdatedValues(speedInMetersPerSecond: values?.speedInMetersPerSecond, cadenceInRpm: values?.cadenceinRPM, distanceInMeters: values?.distanceinMeters)
    }
}



extension CadenceSensor : CBPeripheralDelegate {


    func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
        guard error == nil else {
            sensorDelegate?.errorDiscoveringSensorInformation(NSError(domain: CBErrorDomain, code: 0, userInfo: [NSLocalizedDescriptionKey:NSLocalizedString("Error receiving measurements updates", comment:"")]))

            return
        }
        print("notification status changed for [\(characteristic.uuid)]...")
    }

    func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

        print("Updated [\(characteristic.uuid)]...")

        guard error == nil  , let data = characteristic.value  else {

            return
        }

        handleValueData(data)

    }

    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
        guard error == nil  else {
            sensorDelegate?.errorDiscoveringSensorInformation(error! as NSError)
            return
        }
        // Find the cadence service
        guard let cadenceService =  peripheral.services?.filter({ (service) -> Bool in
            return service.uuid == CBUUID(string: BTConstants.CadenceService)
        }).first else {

            sensorDelegate?.errorDiscoveringSensorInformation(NSError(domain: CBErrorDomain, code: NSNotFound, userInfo: [NSLocalizedDescriptionKey:NSLocalizedString("Cadence service not found for this peripheral", comment:"")]))
            return
        }
        // Discover the cadence service characteristics
        peripheral.discoverCharacteristics(nil, for:cadenceService )
        print("Cadence service discovered")

    }

    func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {

        guard let characteristics = service.characteristics else {
            sensorDelegate?.errorDiscoveringSensorInformation(NSError(domain: CBErrorDomain, code: NSNotFound, userInfo: [NSLocalizedDescriptionKey:NSLocalizedString("No characteristics found for the cadence service", comment:"")]))
            return

        }

        print("Received characteristics");

        // Enable notifications for the measurement characteristic
        for characteristic in characteristics {

            print("Service \(service.uuid). Characteristic [\(characteristic.uuid)]")

            if characteristic.uuid == CBUUID(string: BTConstants.CSCMeasurementUUID) {

                print("Found measurement characteristic. Subscribing...")
                peripheral.setNotifyValue(true, for: characteristic)
                measurementCharasteristic  = characteristic

            }
        }
        sensorDelegate?.sensorReady()

    }

}

还有这个其他代码

    //
//  MainViewController.swift
//  BicycleSpeed


import UIKit
import CoreBluetooth

class MainViewController: UIViewController {


  struct Constants {

    static let ScanSegue = "ScanSegue"
    static let SensorUserDefaultsKey = "lastsensorused"
  }

  var bluetoothManager:BluetoothManager!
  var sensor:CadenceSensor?
  weak var scanViewController:ScanViewController?
  var infoViewController:InfoTableViewController?
  var accumulatedDistance:Double?

  lazy var distanceFormatter:LengthFormatter = {

    let formatter = LengthFormatter()
    formatter.numberFormatter.maximumFractionDigits = 1

    return formatter
  }()

  //@IBOutlet var labelBTStatus:UILabel!
  @IBOutlet var scanItem:UIBarButtonItem!
  @IBOutlet weak var idLabel: UILabel!


  override func viewDidLoad() {

      bluetoothManager = BluetoothManager()
      bluetoothManager.bluetoothDelegate = self
      scanItem.isEnabled = false

  }

  deinit {
    disconnectSensor()
  }

  @IBAction func unwindSegue( _ segue:UIStoryboardSegue ) {
      bluetoothManager.stopScan()
    guard let sensor = (segue as? ScanUnwindSegue)?.sensor else {
      return
    }
    print("Need to connect to sensor \(sensor.peripheral.identifier)")
    connectToSensor(sensor)

  }

  func disconnectSensor( ) {
    if sensor != nil  {
      bluetoothManager.disconnectSensor(sensor!)
      sensor = nil
    }
    accumulatedDistance = nil
  }

  func connectToSensor(_ sensor:CadenceSensor) {

    self.sensor  = sensor
    bluetoothManager.connectToSensor(sensor)
    // Save the sensor ID
    UserDefaults.standard.set(sensor.peripheral.identifier.uuidString, forKey: Constants.SensorUserDefaultsKey)
    UserDefaults.standard.synchronize()

  }
  // TODO: REconnect. Try this every X seconds
  func checkPreviousSensor() {

    guard let sensorID = UserDefaults.standard.object(forKey: Constants.SensorUserDefaultsKey)  as? String else {
      return
    }
    guard let sensor = bluetoothManager.retrieveSensorWithIdentifier(sensorID) else {
      return
    }
    self.sensor = sensor
    connectToSensor(sensor)

  }

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if let infoVC = segue.destination as? InfoTableViewController {
        infoViewController = infoVC
    }
    if segue.identifier == Constants.ScanSegue {

        // Scan segue
      bluetoothManager.startScan()
      scanViewController  = (segue.destination as? UINavigationController)?.viewControllers.first as? ScanViewController
    }

  }

}

extension MainViewController : CadenceSensorDelegate {

  func errorDiscoveringSensorInformation(_ error: NSError) {
      print("An error ocurred disconvering the sensor services/characteristics: \(error)")
  }

  func sensorReady() {
    print("Sensor ready to go...")
    accumulatedDistance = 0.0
  }

  func updateSensorInfo() {
    let name = sensor?.peripheral.name ?? ""
    let uuid = sensor?.peripheral.identifier.uuidString ?? ""

    OperationQueue.main.addOperation { () -> Void in
      self.infoViewController?.showDeviceName(name , uuid:uuid )
    }
  }


  func sensorUpdatedValues( speedInMetersPerSecond speed:Double?, cadenceInRpm cadence:Double?, distanceInMeters distance:Double? ) {

    accumulatedDistance? += distance ?? 0
    let distanceText = (accumulatedDistance != nil && accumulatedDistance! >= 1.0) ? distanceFormatter.string(fromMeters: accumulatedDistance!) : "N/A"
    let speedText = (speed != nil) ? distanceFormatter.string(fromValue: speed!*3.6, unit: .kilometer) + NSLocalizedString("/h", comment:"(km) Per hour") : "N/A"
    let cadenceText = (cadence != nil) ? String(format: "%.2f %@",  cadence!, NSLocalizedString("RPM", comment:"Revs per minute") ) : "N/A"

    OperationQueue.main.addOperation { () -> Void in

      self.infoViewController?.showMeasurementWithSpeed(speedText , cadence: cadenceText, distance: distanceText )
    }
  }


}

extension MainViewController : BluetoothManagerDelegate {

  func stateChanged(_ state: CBCentralManagerState) {
    print("State Changed: \(state)")
    var enabled = false
    var title = ""
    switch state {
    case .poweredOn:
        title = "Bluetooth ON"
        enabled = true
        // When the bluetooth changes to ON, try to reconnect to the previous sensor
        checkPreviousSensor()

    case .resetting:
        title = "Reseeting"
    case .poweredOff:
      title = "Bluetooth Off"
    case .unauthorized:
      title = "Bluetooth not authorized"
    case .unknown:
      title = "Unknown"
    case .unsupported:
      title = "Bluetooth not supported"
    }
    infoViewController?.showBluetoothStatusText( title )
    scanItem.isEnabled = enabled
  }


  func sensorConnection( _ sensor:CadenceSensor, error:NSError?) {
      print("")
    guard error == nil else {
      self.sensor = nil
      print("Error connecting to sensor: \(sensor.peripheral.identifier)")
      updateSensorInfo()
      accumulatedDistance = nil
      return
    }
    self.sensor = sensor
    self.sensor?.sensorDelegate = self
    print("Sensor connected. \(String(describing: sensor.peripheral.name)). [\(sensor.peripheral.identifier)]")
    updateSensorInfo()

    sensor.start()
  }


  func sensorDisconnected( _ sensor:CadenceSensor, error:NSError?) {
    print("Sensor disconnected")
    self.sensor = nil
  }

  func sensorDiscovered( _ sensor:CadenceSensor ) {
      scanViewController?.addSensor(sensor)
  }



}

在 MainViewController.swift 中,有这个 func sensorUpdatedValues 将我想要的三个值转换为字符串并在 InfoTableViewController.swift 中初始化 func showMeasurementWithSpeed 。

我可以只返回函数 sensorUpdateValues 中的三个值,以便能够将它们存储到新变量中吗?

【问题讨论】:

  • 有多种方法可以在类之间共享数据,但我不明白为什么要在类型中创建这些静态变量。这不是一个非常 Swifty 的解决方案
  • @Andras M. 这些返回值我希望它们显示在与另一个类 InfoViewController 关联的 ViewController 中的标签中。

标签: ios swift core-bluetooth


【解决方案1】:

解决此问题的更好方法是将传感器对象传递给 prepare(forSegue:) 中的 InfoTableViewController,然后在 InfoTableViewController 中,您可以调用 sensor.lastMeasurement.speedInMetersPerSecond 或其中的任何其他变量。由于该类是通过引用传递的,因此即使您转换到新的 ViewController,它也会保留数据。

  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let infoVC = segue.destination as? InfoTableViewController {
    infoVC.sensor = self.sensor
}
if segue.identifier == Constants.ScanSegue {

    // Scan segue
  bluetoothManager.startScan()
  scanViewController  = (segue.destination as? UINavigationController)?.viewControllers.first as? ScanViewController
}

} 然后你当然可以在新的 VC 中对这些数据做任何你想做的事情(将值分配给标签或其他东西)

【讨论】:

  • @ Andras M. 谢谢,我想我找到了正确的方法。我编辑了这个问题。你认为这是获得这些价值的正确方法吗?因为据我了解整个项目,在 MainViewController.swift 主体内的 func sensor sensorUpdatedValues 中,将三个值转换为字符串后,有一个 addOperation 调用 InfoTableViewControler 内的函数,将转换后的值作为输入值传递。并且 InfoTableViewController 确实构建了视图,因此相应地显示了值。对吗?
  • @Vinny Twice:我想我终于理解了你的意图:) 最后的测量数据是你在 MainViewController 中的传感器变量的一部分。您应该做的是将传感器从 MainViewController 传递到 infoViewController。您可以通过在 infoViewController 中添加一个名为 sensor 的新 var 来实现,然后在 MainViewController 中找到 prepare 函数并将其更改为:` override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let infoVC = segue.目的地为? InfoTableViewController { infoVC.sensor = self.sensor }`
  • 那么你应该得到 sensor.lastMeasurement.speedInMetersPerSecond 等等。你明白了。
  • @AndrasM。我正在尝试摆脱 InfoTableViewController,并使用 InfoSpeedoViewController 代替内部标签,所以我应该更改 var infoViewController:InfoTableViewController?到 var infoViewController:InfoViewController?并在您编辑的准备中(用于 segue :) 将 InfoTableViewController 更改为 InfoSpeedoViewController。对?并在 infoSpeedoViewController 内部创建一个 var sensor = ?这会是什么类型的?而不是在标签内显示一个值,它将是 speedInfoLabel.text = sensor.lastMeasurement.speedInMetersPerSecond。我做对了吗?
  • 是的,这似乎是正确的。将传感器设置为输入 CadenceSensor!
【解决方案2】:

我相信这是因为您将该 func 声明为实例级函数而不是类/结构级函数。您应该能够简单地添加“静态”关键字,使其可以在您的示例代码中以您使用它的方式访问。即“静态函数 valuesForPreviousMeasurement ...”

** 更新 - 添加了一个简单的示例来显示类和实例函数之间的区别。

// This is an instance function being used.  It's called such because
// you need an actual object instance in order to call the func.
var myCar: Car = Car()
myCar.startEngine()

// This is a class level function being used.  It's called such because
// you don't actually need an object instance: It's simply part of the class.
Car.PriceForModel("HondaCivic")

【讨论】:

  • 不幸的是,将函数声明为静态并没有解决它,它实际上在 hasCrank 和 hasWeel 以及 valueDiffForCurrentSample 上抛出了相同的错误
  • 我将您的代码复制到 xcode 中,我的回答确实纠正了您提到的错误,但您还有多个其他问题。当您将其设为静态时,您将无法在 valuesForPreviousMeasurment 函数中以相同的方式访问其他变量。如果我评论该方法的主体,您的原始错误就会消失。您需要弄清楚您希望这是类级别还是实例级别。
  • 我还必须注释掉您的 mySpeed 变量,该变量还有一个与您如何将 myMeasurement 声明为块有关的问题。
  • @ghostatron 好吧.. 如果我注释掉错误的部分,错误就会消失,但我需要它们。至于您的解决方案,将函数声明为静态并没有使错误消失或改变,它只是在所描述的代码的更多部分添加了相同类型的错误。我在 Xcode 9.1 上,它可以是我们正在使用的不同版本的 swift 吗?我注意到我使用的是 swift 4.0,但将其更改为 sift 3.2 没有任何区别。
  • 我的意思是,在一个地方你使用它就像一个类 func,而在其他地方像一个实例 func。您将其定义为实例 func,这就是它在 func 中工作的原因,而不是您当前将其用作类 func 的地方。如果您将其定义为静态(类 func),那么它将在您现在有错误但不在使用它作为实例方法的方法内部工作。这就是为什么我说你需要决定一个并坚持下去。我提到将函数体注释掉以证明它确实修复了您当前的错误。
【解决方案3】:

终于解决了..比想象的要容易..因为我理解我感兴趣的三个值被传递给我想要摆脱的 infoTableViewController。它们被传递了,已经使用 MainView 控制器中的 sensorUpdatedValues 函数转换为 String

  func sensorUpdatedValues( speedInMetersPerSecond speed:Double?, cadenceInRpm cadence:Double?, distanceInMeters distance:Double? ) {

    accumulatedDistance? += distance ?? 0
    let distanceText = (accumulatedDistance != nil && accumulatedDistance! >= 1.0) ? distanceFormatter.string(fromMeters: accumulatedDistance!) : "N/A"
    let speedText = (speed != nil) ? distanceFormatter.string(fromValue: speed!*3.6, unit: .kilometer) + NSLocalizedString("/h", comment:"(km) Per hour") : "N/A"
    let cadenceText = (cadence != nil) ? String(format: "%.2f %@",  cadence!, NSLocalizedString("RPM", comment:"Revs per minute") ) : "N/A"



    OperationQueue.main.addOperation { () -> Void in

      self.infoViewController?.showMeasurementWithSpeed(speedText , cadence: cadenceText, distance: distanceText )
    }
  }

所以我在我的 InfospeedoViewController 中追踪了该函数(因为 xCode 要求它,因为它存在于 InfoTableViewController 并重新路由到 InfoSpeedoViewController 使其成为必要)并在该函数的主体内我将值连接到标签。

 func showMeasurementWithSpeed( _ speed:String, cadence:String, distance:String  ) {

          speedDisplayLabel.text = speed
          cadenceDisplayLabel.text = cadence
          distanceDisplayLabel.text = distance


//        showDetailText(speed, atSection: Constants.MeasurementsSection, row:Constants.SpeedRow)
//        showDetailText(cadence, atSection: Constants.MeasurementsSection, row:Constants.CadenceRow)
//        showDetailText(distance, atSection: Constants.MeasurementsSection, row:Constants.DistanceRow)

    }

注释掉的部分是旧的 InfoTableViewController 指示填充单元格.. 非常感谢您的帮助。我学到了一些东西并巩固了其他东西。我想我们很努力地试图在错误的位置捕获这些值,但我想这只是因为我打印了所有项目的文件,所以我可以更轻松地跟踪数据流。由于我对 swift 的了解不足,因此无法完全理解代码使其变得更加困难,但我有这种感觉,这种解决方案是逻辑的,因为通常简单的方法是最好的方法,但往往看不到它。 再次感谢 我还有两个想要获得的值。新的冒险开始了..我应该发布另一个问题还是继续这个问题?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-11
    • 2018-04-13
    • 2012-06-23
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    相关资源
    最近更新 更多