【问题标题】:How to view complete contents of NSUserDefaults [duplicate]如何查看 NSUserDefaults 的完整内容 [重复]
【发布时间】:2014-12-24 18:35:47
【问题描述】:

我有一个应用程序,我将所有用户首选项存储在 NSUserDefaults 中。我希望能够(出于调试目的)查看 NSUserDefaults 文件的完整内容。

可以不提供每个密钥就完成吗?

【问题讨论】:

    标签: objective-c nsuserdefaults xcode6.1 ios8.1


    【解决方案1】:
    Can it be done without providing each of the keys?
    

    您可以使用NSUserDefaults 中的dictionaryRepresentation,如下例所示:-

    NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
    [def setObject:@"test1" forKey:@"test1"];
    [def setObject:@"test2" forKey:@"test2"];
    NSLog(@"%@",[[NSUserDefaults standardUserDefaults]dictionaryRepresentation]);
    

    编辑:-

    当使用dictionaryRepresentation时,它会打印出用户默认的完整信息,包括在默认中添加的额外值。

    以下是上述代码的输出。您还可以看到最后一个值,该值额外包含在用户默认值中:-

    AppleAntiAliasingThreshold = 4;
        AppleGCIdleTimeInterval = "1.0";
        AppleLanguages =     (
            en,
            fr,
            de,
            "zh-Hans",
            "zh-Hant",
            ja,
            es,
            it,
            nl,
            ko,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ru,
            pl,
            tr,
            ar,
            th,
            cs,
            hu,
            ca,
            hr,
            el,
            he,
            ro,
            sk,
            uk,
            id,
            ms,
            vi
        );
        AppleLocale = "en_US";
        AppleMeasurementUnits = Inches;
        AppleMetricUnits = 0;
        AppleMiniaturizeOnDoubleClick = 0;
        AppleShowScrollBars = Always;
        AppleTextDirection = 0;
        AppleUserLanguages = 1;
        Country = US;
        MultipleSessionEnabled = 1;
        NSBoldSystemFont = ".LucidaGrandeUI-Bold";
        NSButtonDelay = "0.4";
        NSButtonPeriod = "0.075";
        NSDocumentRevisionsDebugMode = YES;
        NSDragAutoscrollAreaWidth = "5.0";
        NSDragCancelLimit = "100000.0";
        NSDraggingAutoscrollDelay = "0.4";
        NSEnableAutoCollapseOutlineDuringDragsDefault = NO;
        NSEnableAutoExpandOutlineDuringDragsDefault = YES;
        NSFixedPitchFont = "Menlo-Regular";
        NSFixedPitchFontSize = 11;
        NSFont = Helvetica;
        NSFontSize = 12;
        NSInputServerLaunchTimeout = 60;
        NSInterfaceStyle = macintosh;
        NSLanguages =     (
            en,
            fr,
            de,
            "zh-Hans",
            "zh-Hant",
            ja,
            es,
            it,
            nl,
            ko,
            pt,
            "pt-PT",
            da,
            fi,
            nb,
            sv,
            ru,
            pl,
            tr,
            ar,
            th,
            cs,
            hu,
            ca,
            hr,
            el,
            he,
            ro,
            sk,
            uk,
            id,
            ms,
            vi
        );
        NSMargins = "72 72 90 90";
        NSMenuFlashCount = 3;
        NSMenuScrollingOffset = 3;
        NSMenuScrollingSpeed = 5;
        NSNavPanelFileLastListModeForOpenModeKey = 1;
        NSNavPanelFileListModeForOpenMode2 = 1;
        NSNavPanelSidebarKeyForOpen =     (
        );
        NSNavPanelSidebarKeyForSave =     (
        );
        NSNavRecentPlaces =     (
            "~/Documents",
            "~/Documents/sample Project/learning_iOS",
            "~/Desktop/firstPage",
            "~/Desktop/SoftwareDepotIssue",
            "~/Desktop"
        );
        NSPreferredSpellServerVendors =     {
            English = "NeXT-OpenStep";
        };
        NSPreferredWebServices =     {
            NSWebServicesProviderWebSearch =         {
                NSDefaultDisplayName = Google;
                NSProviderIdentifier = "com.google.www";
            };
        };
        NSQuotedKeystrokeBinding = "^q";
        NSRequireAutoCollapseOutlineAfterDropsDefault = NO;
        NSResetIncrementalSearchOnFailure = YES;
        NSScrollAnimationEnabled = YES;
        NSScrollerButtonAcceleration = 8;
        NSScrollerButtonDelay = "0.5";
        NSScrollerButtonPeriod = "0.05";
        NSScrollerHasSeparateArrows = YES;
        NSScrollerKnobCount = 2;
        NSScrollerKnobDelay = "0.001";
        NSSmartCMYKColorConversion = YES;
        NSSystemFont = ".LucidaGrandeUI";
        NSSystemFontSize = 13;
        NSUIHeartBeatCycle = "0.03";
        NSUseCocoaInputServers = YES;
        NSUserDictionaryReplacementItems =     (
        );
        NSWindowResizeTime = ".20";
        NavPanelFileListModeForOpenMode = 1;
        SGTRecentFileSearches =     (
                    {
                attributes =             (
                    kMDItemDisplayName
                );
                enforceStrictMatch = 0;
                exactMatch = 0;
                name = istsu;
                scope = 4;
                type = "com.apple.finder";
                values =             (
                    istsu
                );
            }
        );
        WebKitAVFoundationEnabled = 1;
        WebKitAccelerated2dCanvasEnabled = 0;
        WebKitAcceleratedCompositingEnabled = 1;
        WebKitAcceleratedDrawingEnabled = 0;
        WebKitAllowAnimatedImageLoopingPreferenceKey = 1;
        WebKitAllowAnimatedImagesPreferenceKey = 1;
        WebKitAllowFileAccessFromFileURLs = 1;
        WebKitAllowUniversalAccessFromFileURLs = 1;
        WebKitApplicationCacheDefaultOriginQuota = 9223372036854775807;
        WebKitApplicationCacheTotalQuota = 9223372036854775807;
        WebKitApplicationChromeModeEnabledPreferenceKey = 0;
        WebKitAsynchronousSpellCheckingEnabled = 0;
        WebKitAuthorAndUserStylesEnabledPreferenceKey = 1;
        WebKitBackForwardCacheExpirationIntervalKey = 1800;
        WebKitBackspaceKeyNavigationEnabled = 1;
        WebKitCSSCompositingEnabled = 1;
        WebKitCSSCustomFilterEnabled = 1;
        WebKitCSSGridLayoutEnabled = 0;
        WebKitCSSRegionsEnabled = 1;
        WebKitCacheModelPreferenceKey = 0;
        WebKitCanvasUsesAcceleratedDrawing = 0;
        WebKitCursiveFont = "Apple Chancery";
        WebKitDNSPrefetchingEnabled = 0;
        WebKitDOMPasteAllowedPreferenceKey = 0;
        WebKitDatabasesEnabledPreferenceKey = 1;
        WebKitDefaultFixedFontSize = 13;
        WebKitDefaultFontSize = 16;
        WebKitDefaultTextEncodingName = "ISO-8859-1";
        WebKitDeveloperExtrasEnabledPreferenceKey = 0;
        WebKitDiagnosticLoggingEnabled = 0;
        WebKitDisplayImagesKey = 1;
        WebKitEditableLinkBehavior = 0;
        WebKitEnableInheritURIQueryComponent = 0;
        WebKitExperimentalNotificationsEnabledPreferenceKey = 0;
        WebKitFantasyFont = Papyrus;
        WebKitFixedFont = Courier;
        WebKitFrameFlatteningEnabled = 0;
        WebKitFullScreenEnabled = 0;
        WebKitHiddenPageCSSAnimationSuspensionEnabled = 0;
        WebKitHiddenPageDOMTimerThrottlingEnabled = 0;
        WebKitHyperlinkAuditingEnabled = 1;
        WebKitJavaEnabled = 1;
        WebKitJavaScriptCanAccessClipboard = 0;
        WebKitJavaScriptCanOpenWindowsAutomatically = 1;
        WebKitJavaScriptEnabled = 1;
        WebKitJavaScriptExperimentsEnabledPreferenceKey = 0;
        WebKitKerningAndLigaturesEnabledByDefault = 1;
        WebKitLoadSiteIconsKey = 0;
        WebKitLocalFileContentSniffingEnabledPreferenceKey = 0;
        WebKitLocalStorageEnabledPreferenceKey = 1;
        WebKitLowPowerVideoAudioBufferSizeEnabled = 0;
        WebKitMediaPlaybackAllowsInline = 1;
        WebKitMediaPlaybackRequiresUserGesture = 0;
        WebKitMinimumFontSize = 0;
        WebKitMinimumLogicalFontSize = 9;
        WebKitNotificationsEnabled = 1;
        WebKitOfflineWebApplicationCacheEnabled = 0;
        WebKitPDFDisplayMode = 1;
        WebKitPDFScaleFactor = 0;
        WebKitPageCacheSupportsPluginsPreferenceKey = 1;
        WebKitPictographFont = "Apple Color Emoji";
        WebKitPlugInSnapshottingEnabled = 0;
        WebKitPluginsEnabled = 1;
        WebKitPrivateBrowsingEnabled = 0;
        WebKitQTKitEnabled = 1;
        WebKitRegionBasedColumnsEnabled = 0;
        WebKitRequestAnimationFrameEnabled = 1;
        WebKitRespectStandardStyleKeyEquivalents = 0;
        WebKitSansSerifFont = Helvetica;
        WebKitScreenFontSubstitutionEnabled = 0;
        WebKitSerifFont = Times;
        WebKitShouldDisplayCaptions = 0;
        WebKitShouldDisplaySubtitles = 0;
        WebKitShouldDisplayTextDescriptions = 0;
        WebKitShouldPrintBackgroundsPreferenceKey = 0;
        WebKitShouldRespectImageOrientation = 0;
        WebKitShowDebugBorders = 0;
        WebKitShowRepaintCounter = 0;
        WebKitShowsToolTipOverTruncatedText = 0;
        WebKitShowsURLsInToolTips = 0;
        WebKitShrinksStandaloneImagesToFit = 0;
        WebKitSpatialNavigationEnabled = 0;
        WebKitStandardFont = Times;
        WebKitStorageBlockingPolicy = 0;
        WebKitSuppressesIncrementalRendering = 0;
        WebKitTabToLinksPreferenceKey = 0;
        WebKitTextAreasAreResizable = 0;
        WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey = 1;
        WebKitUseLegacyTextAlignPositionedElementBehavior = 0;
        WebKitUsePreHTML5ParserQuirks = 0;
        WebKitUseSiteSpecificSpoofing = 0;
        WebKitUserStyleSheetEnabledPreferenceKey = 0;
        WebKitUserStyleSheetLocationPreferenceKey = "";
        WebKitUsesEncodingDetector = 0;
        WebKitUsesPageCachePreferenceKey = 1;
        WebKitWantsBalancedSetDefersLoadingBehavior = 0;
        WebKitWebArchiveDebugModeEnabledPreferenceKey = 0;
        WebKitWebAudioEnabled = 0;
        WebKitWebGLEnabled = 0;
        WebKitWebSecurityEnabled = 1;
        WebKitXSSAuditorEnabled = 1;
        WebKitZoomsTextOnly = 1;
        "com.apple.AppleModemSettingTool.LastCountryCode" = US;
        "com.apple.ColorSync.Devices" =     {
            "Device.cmra.00000000-0000-0000-0000-000000533630" =         {
                DeviceDescriptions =             {
                    "en_US" = "NO NAME";
                };
                FactoryProfiles =             {
                    555810816 =                 {
                        DeviceModeDescriptions =                     {
                            "en_US" = Default;
                        };
                        DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
                    };
                    DeviceDefaultProfileID = 555810816;
                };
            };
            "Device.cmra.30303441-3030-3930-4637-393830304637" =         {
                DeviceDescriptions =             {
                    "en_US" = "Lumia 520";
                };
                FactoryProfiles =             {
                    555810816 =                 {
                        DeviceModeDescriptions =                     {
                            "en_US" = Default;
                        };
                        DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
                    };
                    DeviceDefaultProfileID = 555810816;
                };
            };
            "Device.cmra.37616133-3566-6339-6362-303662336639" =         {
                DeviceDescriptions =             {
                    "en_US" = iPhone;
                };
                FactoryProfiles =             {
                    555810816 =                 {
                        DeviceModeDescriptions =                     {
                            "en_US" = Default;
                        };
                        DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
                    };
                    DeviceDefaultProfileID = 555810816;
                };
            };
        };
        "com.apple.TimeZonePref.Last_Selected_City" =     (
            "37.36883",
            "-122.0363",
            0,
            "America/Los_Angeles",
            US,
            Sunnyvale,
            "U.S.A.",
            Sunnyvale,
            "U.S.A.",
            "DEPRECATED IN 10.6"
        );
        "com.apple.preferences.timezone.selected_city" =     {
            CountryCode = US;
            GeonameID = 5400075;
            Latitude = "37.36883";
            LocalizedNames =         {
                ar = "\U0633\U0627\U0646\U064a\U0641\U064a\U0644";
                ca = Sunnyvale;
                cs = Sunnyvale;
                da = Sunnyvale;
                de = Sunnyvale;
                el = Sunnyvale;
                en = Sunnyvale;
                es = Sunnyvale;
                fi = Sunnyvale;
                fr = Sunnyvale;
                he = "\U05e1\U05d0\U05e0\U05d9\U05d5\U05d5\U05dc";
                hr = Sunnyvale;
                hu = Sunnyvale;
                id = Sunnyvale;
                it = Sunnyvale;
                ja = "\U30b5\U30cb\U30fc\U30d9\U30fc\U30eb";
                ko = "\Uc11c\Ub2c8\Ubca0\Uc77c";
                ms = Sunnyvale;
                nb = Sunnyvale;
                nl = Sunnyvale;
                pl = Sunnyvale;
                pt = Sunnyvale;
                "pt-PT" = Sunnyvale;
                ro = Sunnyvale;
                ru = "\U0421\U0430\U043d\U043d\U0438\U0432\U0435\U0439\U043b";
                sk = Sunnyvale;
                sv = Sunnyvale;
                th = Sunnyvale;
                tr = Sunnyvale;
                uk = "\U0421\U0430\U043d\U043d\U0456\U0432\U0435\U0439\U043b";
                vi = Sunnyvale;
                "zh-Hans" = "\U6851\U5c3c\U7ef4\U5c14";
                "zh-Hant" = "\U6851\U5c3c\U7dad\U723e";
            };
            Longitude = "-122.0363";
            Name = Sunnyvale;
            Population = 140081;
            RegionalCode = CA;
            TimeZoneName = "America/Los_Angeles";
            Version = 1;
        };
        "com.apple.springing.delay" = "0.5";
        "com.apple.springing.enabled" = 1;
        "com.apple.trackpad.enableSecondaryClick" = 1;
        "com.apple.trackpad.fiveFingerPinchSwipeGesture" = 2;
        "com.apple.trackpad.fourFingerHorizSwipeGesture" = 2;
        "com.apple.trackpad.fourFingerPinchSwipeGesture" = 2;
        "com.apple.trackpad.fourFingerVertSwipeGesture" = 2;
        "com.apple.trackpad.momentumScroll" = 1;
        "com.apple.trackpad.pinchGesture" = 1;
        "com.apple.trackpad.rotateGesture" = 1;
        "com.apple.trackpad.scrollBehavior" = 2;
        "com.apple.trackpad.threeFingerDragGesture" = 0;
        "com.apple.trackpad.threeFingerHorizSwipeGesture" = 2;
        "com.apple.trackpad.threeFingerTapGesture" = 2;
        "com.apple.trackpad.threeFingerVertSwipeGesture" = 2;
        "com.apple.trackpad.twoFingerDoubleTapGesture" = 1;
        "com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture" = 3;
        "com.apple.trackpad.version" = 5;
        "com.apple.updatesettings_did_disable_ftp" = 1;
        test1 = test1;
        test2 = test2;
    

    【讨论】:

    • 谢谢...像冠军一样工作!
    猜你喜欢
    • 1970-01-01
    • 2022-01-13
    • 2019-06-15
    • 2017-05-12
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2018-04-03
    • 2018-03-05
    相关资源
    最近更新 更多