gpt4 book ai didi

快速组合代码

转载 作者:行者123 更新时间:2023-11-28 12:08:45 25 4
gpt4 key购买 nike

我正在使用 Xcode/Swift 编写一个应用程序。我想将这两个代码功能组合成一个更小的代码功能,以消除重复代码。

第一段代码:

@IBAction func StopRecording(_ sender: Any) {
recordButton.isEnabled = true
stopRecordingButton.isEnabled = false
recordingLabel.text = "Tap to record"
audioRecorder.stop()
let audioSession = AVAudioSession.sharedInstance()
try! audioSession.setActive(false)
}

第二段代码:

@IBAction func recordAudio(_ sender: AnyObject) {
recordingLabel.text = "Recording in progress"
stopRecordingButton.isEnabled = true
recordButton.isEnabled = false

这是我的错误尝试:

@IBAction func recordAudio(_ sender: AnyObject) {
func SetLabel(recordButton: Bool, recordingText:String)
if recordButton = true
recordingLabel.text = "Recording in progress"
stopRecordingButton.isEnabled = true
recordButton.isEnabled = false
else if {
@IBAction func StopRecording(_ sender: Any) {
recordButton.isEnabled = true
stopRecordingButton.isEnabled = false
recordingLabel.text = "Tap to record"
audioRecorder.stop()
let audioSession = AVAudioSession.sharedInstance()
try! audioSession.setActive(false)
}
}

{

最佳答案

试试这个:

func updateButtons(recording: Bool) {
recordingLabel.text = recording ? "Recording in progress" : "Tap to record"
stopRecordingButton.isEnabled = recording
recordButton.isEnabled = !recording
}

关于快速组合代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48952201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com