我寫函式
actual fun setItem(key: String, value: String) {
NSUserDefaults.standardUserDefaults.setValue(value, key)
}
并得到了這個錯誤。我認為值字串并與 Any 一起使用
Showing Recent Messages
The following Kotlin source sets were configured but not added to any Kotlin compilation:
* androidAndroidTestRelease
* androidTestFixtures
* androidTestFixturesDebug
* androidTestFixturesRelease
You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
> Task :shared:compileKotlinIosX64 FAILED
e: /Users/anh.nguyen25/Desktop/momo-app-vix/shared/src/iosMain/kotlin/vn/momo/core/modules/storage/FastStorage.kt: (14, 45): Overload resolution ambiguity:
public external fun NSObject.setValue(value: Any?, forKey: String): Unit defined in platform.Foundation
public external fun NSObject.setValue(value: Any?, forKeyPath: String): Unit defined in platform.Foundation
public external fun NSObject.setValue(value: Any?, forUndefinedKey: String): Unit defined in platform.Foundation
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':shared:compileKotlinIosX64'.
> Compilation finished with errors
uj5u.com熱心網友回復:
setValue是與用戶默認值無關的 KVO 方法。
將其替換為setObject:
NSUserDefaults.standardUserDefaults.setObject(value, key)
ps如果你需要使用setValue或者你會遇到其他方法同樣的問題,你可以通過提供第二個引數名稱來指定需要的方法,例如setValue(value, forKeyPath = key)
uj5u.com熱心網友回復:
除了上面的答案,如果您正在尋找即插即用的 KMP 鍵值存盤,多平臺設定值得一試。它還NSUserDefaults在引擎蓋下使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/447587.html
標籤:IOS 迅速 科特林 kotlin-多平台
上一篇:當至少一個賽普拉斯測驗失敗時,在AWSCodeBuild中獲取“COMMAND_EXECUTION_ERROR...原因:退出狀態1”
