小编Kyr*_*das的帖子

在iOS 7上使用AVSpeechSynthesizer但保留iOS 6的兼容性

你好我理解TTS仅在iOS 7中可用,但我过去使用了很多apis,检查该类是否可用并设法保留以前版本的兼容性,但是使用AVSpeechSynthesizer它似乎不起作用,请你帮我使用适用于iOS 7的TTS并通过在iOS 6中禁用它来保持兼容性,非常感谢.

这是我的代码,但它似乎不起作用

    if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)) {
    if([AVSpeechSynthesizer class]) {
        AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
        AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:text];
        utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
        utterance.rate = AVSpeechUtteranceDefaultSpeechRate/2;
        utterance.pitchMultiplier = 0.9;
        utterance.preUtteranceDelay = 0;
        utterance.postUtteranceDelay = 0;
        [synth speakUtterance:utterance];
    } else {
        // Feature not available, do something else
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经在我的项目中链接了avfoundation并设置了部署目标iOS 6,它似乎仅在iOS 7设备上运行时工作,如果它的iOS 6崩溃了.

这是我得到的错误消息

dyld: Symbol not found: _AVSpeechUtteranceDefaultSpeechRate
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios ios7

4
推荐指数
1
解决办法
983
查看次数

使用 Swift 4 按 Double 属性值对自定义对象数组进行排序

我试图将自己从objective-c 移动到swift,我有一个名为Market 的自定义类,这个类包含一些属性,

class Market  {
    var name = String?
    var volume = Double?
}
Run Code Online (Sandbox Code Playgroud)

它们中的很多都存储在一个数组中,我试图通过 volume 属性对这个数组进行升序或降序排序。

我试过了,但不起作用,二元运算符“>”不能应用于两个“双?” 操作数

self.market.sort(by:{$0.volume > $1.volume})
Run Code Online (Sandbox Code Playgroud)

最方便的快捷方式是什么?

arrays sorting double swift

1
推荐指数
1
解决办法
1531
查看次数

标签 统计

arrays ×1

double ×1

ios ×1

ios7 ×1

iphone ×1

objective-c ×1

sorting ×1

swift ×1

xcode ×1