玩弄那里的例子。找到了一个项目,该项目的类是可绑定的对象,没有给出任何错误。现在Xcode 11 beta 4已经发布,我得到了错误:
类型“ UserSettings”不符合协议“ BindableObject”
它在错误上有一个修复按钮,当您单击它时,它会添加
typealias PublisherType = <#type#>
Run Code Online (Sandbox Code Playgroud)
希望您填写类型。
类型是什么?
class UserSettings: BindableObject {
let didChange = PassthroughSubject<Void, Never>()
var score: Int = 0 {
didSet {
didChange.send()
}
}
}
Run Code Online (Sandbox Code Playgroud) 所以我只想尝试使用Swift的AVSpeechSynthesizer.我无法弄清楚如何为AVSpeechUtterance设置短语.
@IBAction func buttonSpeakClicked(sender:UIButton)
{
var mySpeechSynthesizer:AVSpeechSynthesizer = AVSpeechSynthesizer()
var myString:String = "This is the phrase to say"
var mySpeechUtterance:AVSpeechUtterance = AVSpeechUtterance(string:myString)
println("\(mySpeechUtterance.speechString)")
println("My string - \(myString)")
mySpeechSynthesizer .speakUtterance(mySpeechUtterance)
}
Run Code Online (Sandbox Code Playgroud)
第一次打印 - 没有
第二个println - 这就是要说的那句话
文档说init(字符串字符串:String!),但我无法弄清楚将它放在何处
处理示例应用程序。目标是从 Master 中的 CoreData 中提取一个列表,然后单击一个列表以转到详细信息,您可以在其中编辑信息并保存。当您在细节中编辑“名称”时,它不仅会更新细节以反映更改,而且还会反映母版上的更改。我已经尝试了很多方法来实现这一点,但到目前为止还没有找到答案。
// Code generation is turned OFF in the xcdatamodeld file
public class EntityName: NSManagedObject, Identifiable {
@NSManaged public var name: String
@NSManaged public var active: Bool
}
extension EntityName {
static func allEntityNameFetchRequest() -> NSFetchRequest<EntityName> {
let request: NSFetchRequest<EntityName> = EntityName.fetchRequest() as! NSFetchRequest<EntityName>
request.sortDescriptors = [NSSortDescriptor(key: "name", ascending: true)]
return request
}
}
struct MasterView: View {
@Environment(\.managedObjectContext) var managedObjectContext
@FetchRequest(fetchRequest: EntityName.allEntityNameFetchRequest()) var allEntityNames: FetchedResults<EntityName>
var body: some View {
NavigationView {
List {
ForEach(self.allEntityNames) …Run Code Online (Sandbox Code Playgroud) 我正在尝试检查以确保用户已授权警报和徽章.一旦得到它,我在弄清楚如何处理当前设置时遇到了问题.
let settings = UIApplication.sharedApplication().currentUserNotificationSettings()
println(settings)
// Prints - <UIUserNotificationSettings: 0x7fd0a268bca0; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>
if settings.types == UIUserNotificationType.Alert // NOPE - this is the line that needs an update
{
println("Yes, they have authorized Alert")
}
else
{
println("No, they have not authorized Alert. Explain to them how to set it.")
}
Run Code Online (Sandbox Code Playgroud) 去年我问了一个关于如何将语音保存到文件的问题。 堆栈溢出问题 - 将语音合成录制到保存的文件中
感谢 kakaiikaka 的回答。虽然它确实有效,但缓冲时出现了一些错误。以下代码隔离了该问题。在 iOS 16 中,尽管存在错误,但它确实可以按预期工作。我按预期打印的完成处理程序。以下错误打印了 20 次左右。
2023-06-17 15:35:33.811838-0400 RecordSpeechFix [3899:1958883] [AXTTSCommon] TTSPlaybackEnqueueFullAudioQueueBuffer:错误-66686排队缓冲区
iOS 17(第一个测试版)存在一个更具描述性的错误,并且它不起作用。完成处理程序不打印。以下错误打印了 20 次左右。
输入数据过程返回不一致的 512 个数据包(2,048 字节);按每个数据包 2 字节计算,实际上是 1,024 个数据包
我假设这是同一个问题。修复 iOS16 的错误也将修复 iOS17 的错误。我的这个假设可能是错误的。
//
// ContentView.swift
// RecordSpeechFix
//
// Created by Dennis Sargent on 6/16/23.
//
import AVFoundation
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Record Speech")
}
.padding()
.onTapGesture {
saveSpeechUtteranceToFile(phrase: "This produces warnings.") {
print("In …Run Code Online (Sandbox Code Playgroud)