Что за ошибка в протоколе?

protocol
swift4

#1

не могу понять, что за ошибка в этой строке:

Текст сообщения об ошибке - Cannot convert value of type ‘Int.Type’ to expected argument type ‘Int’

И почему Xcode упорно перебивает параметры функции heartRateUpdated(to bpm: Int) на (to: Int)?

Вот полный код:

import UIKit

protocol HeartRateReceiverDelegate {
    func heartRateUpdated(to bpm: Int)
}

class HeartRateReceiver {
    var delegate: HeartRateReceiverDelegate?
    
    var currentHR: Int? {
        didSet {
            if let currentHR = currentHR {
                print("The most recent heart rate reading is \(currentHR).")
                delegate?.heartRateUpdated(to: Int)
            } else {
                print("Looks like we can't pick up a heart rate.")
            }
        }
    }
    
    func startHeartRateMonitoringExample() {
        for _ in 1...10 {
            let randomHR = 60 + Int(arc4random_uniform(UInt32(15)))
            currentHR = randomHR
            Thread.sleep(forTimeInterval: 2)
        }
    }
}

class HeartRateViewController: UIViewController, HeartRateReceiverDelegate {
    
    var heartRateLabel: UILabel = UILabel()
    
    func heartRateUpdated(to bpm: Int) {
        heartRateLabel.text = "The user has been shown a heart rate of \(heartRateReceiver.currentHR!)"
    }
}

var heartRateReceiver = HeartRateReceiver()
heartRateReceiver.startHeartRateMonitoringExample()

var heartRateViewController = HeartRateViewController()

heartRateReceiver.delegate = heartRateViewController

Что это может быть?


#2

Вам ошибка говрит:
я не могу конвертировать тип Int в значение типа Int
Замените эту строку

 delegate?.heartRateUpdated(to: Int)

На

delegate?.heartRateUpdated(to: currentHR)

#3

блин, да, это я заработался)) Сэнкс.

А не могли бы Вы еще подсказать вот в этом фрагменте спецификации:

Now make HeartRateViewController adopt the protocol you’ve just created. Inside the body of the required method you should set the text of heartRateLabel and print “The user has been shown a heart rate of .”

В данном случае print подразумевает отдельную команду внутри требуемого метода или имеется в виду, что печатать нужно на lable как сейчас в коде?

func heartRateUpdated(to bpm: Int ) {
        heartRateLabel.text = "The user has been shown a heart rate of \(heartRateReceiver.currentHR!)"
    }

Дело в том, что в итоге программа должна выводить два ряда записей согласно этой спецификации:

observe what is printed to the console. Every time that currentHR gets set, you should see both a printout of the most recent heart rate, and the print statement stating that the heart rate was shown to the user.

Но она этого почему-то не делает.


#4

Label - на UI, print - в консоли.