반응형
NSUserDefaults의 모든 값을 가져올 수 있는 방법이 있습니까?
저장한 모든 값을 인쇄하고 싶습니다.NSUserDefaults특정 키를 제공하지 않음
다음을 사용하여 배열의 모든 값을 인쇄하는 것과 같습니다.for루프. 그렇게 할 수 있는 방법이 있습니까?
목표 C
모든 값:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allValues]);
모든 키:
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
모든 키 및 값:
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
사용 대상:
NSArray *keys = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys];
for(NSString* key in keys){
// your code here
NSLog(@"value: %@ forKey: %@",[[NSUserDefaults standardUserDefaults] valueForKey:key],key);
}
스위프트
모든 값:
print(UserDefaults.standard.dictionaryRepresentation().values)
모든 키:
print(UserDefaults.standard.dictionaryRepresentation().keys)
모든 키 및 값:
print(UserDefaults.standard.dictionaryRepresentation())
사용할 수 있는 항목:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *defaultAsDic = [defaults dictionaryRepresentation];
NSArray *keyArr = [defaultAsDic allKeys];
for (NSString *key in keyArr)
{
NSLog(@"key [%@] => Value [%@]",key,[defaultAsDic valueForKey:key]);
}
키만 인쇄
NSLog(@"%@", [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] allKeys]);
키 및 값
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
다음을 사용하여 앱에서 사용할 수 있는 모든 콘텐츠를 기록할 수 있습니다.
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
언급URL : https://stackoverflow.com/questions/17522286/is-there-a-way-to-get-all-values-in-nsuserdefaults
반응형
'source' 카테고리의 다른 글
| 언플러그드에서 행이 소프트 삭제되었는지 확인하는 방법은 무엇입니까? (0) | 2023.08.05 |
|---|---|
| PowerShell에서 %ProgramFiles(x86)%와 같은 괄호가 있는 환경 변수 이름? (0) | 2023.08.05 |
| malloc "double free" 오류의 원인을 찾는 방법은 무엇입니까? (0) | 2023.08.05 |
| docker-compose.yml의 환경 변수 재사용 (0) | 2023.08.05 |
| 노드 JS 버전 번호가 혼동 (0) | 2023.08.05 |