Is it possible to access SharedPreferences
saved from Flutter accessed in Swift code of plugin? In Android we have FILE
mode for SharedPreferences
.
Any similar feature in Swift 4?
The shared_preferences
uses NSUserDefaults
on iOS to store the data. You can easily access it with Swift like this:
let name = NSUserDefaults.standard.string(forKey: "flutter.test")
print(name)
It would also make sense to use the optional binding to get the value safely:
if let name = NSUserDefaults.standard.string(forKey: "flutter.test") {
print(name)
}
Note, that if you use the key test
in your flutter/dart code you would need to add the flutter.
prefix to the key, as the shared_preferences
plugin prefixes every key with it (see this line in the source code)
Use UserDefaults on Swift.
UserDefaults.standard.object(forKey:"flutter.key"))
key = key used em flutter to shared preferences. You need to use flutter prefix on key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With