Key Value API มี API การจัดการข้อมูลที่กำหนดเองใหม่สำหรับออบเจ็กต์อุปกรณ์ ห้อง และ การทำงานอัตโนมัติ วงจรของข้อมูลที่กำหนดเองจะจำกัดไว้เฉพาะ วงจรของออบเจ็กต์ที่เชื่อมโยงด้วย เช่น ข้อมูลที่กำหนดเอง (เช่น "ห้องของลูซี่") ที่เชื่อมโยงกับออบเจ็กต์ Room จะถูกลบ ย้าย หรือโอน (ในโครงสร้างต่างๆ) พร้อมกับออบเจ็กต์ Room โดยอัตโนมัติ
การเปลี่ยนแปลง Swift API มุ่งเน้นไปที่ตัวควบคุม
CustomAppData
และมีส่วนขยายสำหรับออบเจ็กต์ที่ข้อมูลแอปพลิเคชันที่กำหนดเอง
เป็นของ รวมถึงฟังก์ชันสร้าง อ่าน อัปเดต และลบ (CRUD) มาตรฐาน
ตัวอย่างอุปกรณ์
guard let device = home.devices.first(where: { $0.name == deviceName }) else { return }
var response = try await device.customAppData[key]
print("Before: \(response)")
try await device.customAppData.update(key: key, value: value)
response = try await device.customAppData[key]
print("After: \(response)")
try await device.customAppData.delete(key)
ตัวอย่างห้อง
guard let room = home.rooms.first(where: { $0.name == roomName }) else { return }
try await room.customAppData.update(key: "nickname", value: "Lucy's Room")
let response = try await room.customAppData["nickname"]
try await room.customAppData.delete("nickname")
ตัวอย่างการทำงานอัตโนมัติ
guard let automation = home.automations.first(where: { $0.name == automationName }) else { return }
var response = try await automation.customAppData[key]
print("Before: \(response)")
try await automation.customAppData.update(key: key, value: value)
response = try await automation.customAppData[key]
print("After: \(response)")
try await automation.customAppData.delete(key)
ข้อจำกัด
- คีย์ต้องเป็นสตริงของอักขระ UTF-8 ที่ถูกต้อง โดยมีความยาวสูงสุด 128 คีย์อาจเป็นสตริงว่างได้
- ค่าต้องเป็นสตริงของอักขระ UTF-8 ที่ถูกต้อง โดยมีความยาวสูงสุด 1, 024 อักขระ ค่าอาจเป็นสตริงว่างเปล่า
- แต่ละออบเจ็กต์มีคู่คีย์-ค่าได้ 10 แถว