Sharing Data with AppGroup

后端 未结 1 397
傲寒
傲寒 2021-01-23 00:51

I want to share one variable from my UIKit File to my Widget Extension created with SwiftUI. I followed this here. Please look at the answer from J Arango.

But i dont und

1条回答
  •  孤街浪徒
    2021-01-23 01:31

    1. Save data to UserDefaults in your main App:
    UserDefaults(suiteName: )!.set("test", forKey: "test")
    
    1. Read data from UserDefaults in your Widget:
    let testStr = UserDefaults(suiteName: )!.string(forKey: "test")
    

    If you want to save other types see:

    • How can I use UserDefaults in Swift?

    0 讨论(0)
提交回复
热议问题