Skip to content

Commit

Permalink
Fill the blank with iOS preference remove
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Apr 11, 2020
1 parent 349070d commit 0f9cff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/preferences_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package app

import (
"errors"
"unsafe"

"fyne.io/fyne"
Expand All @@ -22,6 +21,7 @@ int getPreferenceInt(const char* key, int fallback);
void setPreferenceInt(const char* key, int value);
const char* getPreferenceString(const char* key, const char* fallback);
void setPreferenceString(const char* key, const char* value);
void removePreferenceValue(const char* key);
*/
import "C"

Expand Down Expand Up @@ -107,9 +107,11 @@ func (p *iOSPreferences) SetString(key string, value string) {
C.setPreferenceString(cKey, cValue)
}

// TODO: Implement the support for RemoveValue on iOS to make it work across all platforms.
func (p *iOSPreferences) RemoveValue(key string) {
fyne.LogError("Calling RemoveValue() on iOS", errors.New("It is currently not supported to use RemoveValue on iOS"))
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))

C.removePreferenceValue(cKey)
}

func newPreferences() *iOSPreferences {
Expand Down
5 changes: 5 additions & 0 deletions app/preferences_ios.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ void setPreferenceString(const char* key, const char* value) {
NSString *nsval = [NSString stringWithUTF8String:value];
[[NSUserDefaults standardUserDefaults] setObject:nsval forKey:nskey];
}

void removePreferenceValue(const char* key) {
NSString *nskey = [NSString stringWithUTF8String:key];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:nskey];
}

0 comments on commit 0f9cff2

Please sign in to comment.