Launch Arguments & NSUserDefaults by Franck Lefebvre
-
Upload
cocoaheads-france -
Category
Technology
-
view
5.088 -
download
4
description
Transcript of Launch Arguments & NSUserDefaults by Franck Lefebvre
![Page 1: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/1.jpg)
Launch Arguments & NSUserDefaults
Frank Lefebvre
CocoaHeads ParisSeptember 2014
![Page 2: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/2.jpg)
Xcode Schemes
[0] executable path[1] argument1[2] argument2[3] argument3
![Page 3: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/3.jpg)
Xcode Schemes
[0] executable path[1] argument1[2] argument2[3] argument3
![Page 4: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/4.jpg)
Xcode Schemes
[0] executable path[1] word1 word2 word3
![Page 5: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/5.jpg)
Obtain launch arguments in Cocoa application
•main
![Page 6: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/6.jpg)
Main: Objective-C
int main(int argc, char * argv[]){ @autoreleasepool { for (int i = 0; i < argc; i ++) { NSLog(@"%s", argv[i]); } } return 0;}
![Page 7: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/7.jpg)
Main: Swift
// C_ARGC: CInt// C_ARGV: UnsafeMutablePointer// <UnsafeMutablePointer<Int8>>
for i in 0..<Int(C_ARGC) { let arg = String.fromCString(C_ARGV[i]) println(\(arg))}
![Page 8: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/8.jpg)
Obtain launch arguments in Cocoa application
•main
•NSProcessInfo
![Page 9: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/9.jpg)
NSProcessInfo
NSArray* args = [NSProcessInfo processInfo].arguments
let args = NSProcessInfo.processInfo().arguments// args: [AnyObject]!
![Page 10: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/10.jpg)
Process (Swift)
// Process.arguments: [String]
for arg in Process.arguments { println(\(arg))}
![Page 11: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/11.jpg)
Obtain launch arguments in Cocoa application
•main
•NSProcessInfo
•NSUserDefaults
![Page 12: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/12.jpg)
NSUserDefaults
•Arguments: -option value
id value = [[NSUserDefaults standardDefaults] objectForKey:@"option"];
•Type conversion
NSString* value = [[NSUserDefaults standardUserDefaults] stringForKey:@"option"];
•Complex types
![Page 13: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/13.jpg)
Defaults Domains
• argument domain
• application domain
•global domain
• language domain
• registration domain
![Page 14: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/14.jpg)
Usages
•Override user default
•Application Configuration
• Language & Localization Testing
•Debugging
![Page 15: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/15.jpg)
Application Configuration
• Production vs Staging vs Development
•Web Service URL
• Logging configuration
• registerDefaults: production settings
![Page 16: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/16.jpg)
Localization
• -AppleLanguage (en)
• -AppleLocale fr_FR
• -NSDoubleLocalizedStrings YES
• -NSShowNonLocalizedStrings YES
• -AppleTextDirection YES
• -NSForceRightToLeftWritingDirection YES
![Page 17: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/17.jpg)
Debugging : Core Data
•-com.apple.CoreData.SQLDebug 3
•-com.apple.CoreData.Ubiquity.LogLevel 3
•-com.apple.CoreData.SyntaxColoredLogging YES
•-com.apple.CoreData.MigrationDebug
![Page 18: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/18.jpg)
Debugging : Views
•UIKit
•-UIViewShowAlignmentRects YES
•AppKit (Yosemite)
•-NSResponderDebugResponderLoops YES
![Page 19: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/19.jpg)
Mining for Hidden Gems
@implementation NSUserDefaults (Spying)
#pragma GCC diagnostic push#pragma GCC diagnostic ignored "-Wobjc-protocol-method-implementation"
- (NSArray*)arrayForKey:(NSString *)defaultName{ [self logDefault:defaultName withType:@"array"]; return nil;}
// ...
#pragma GCC diagnostic pop
@end
![Page 20: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/20.jpg)
Results
UIDisableLegacyTextView WebKitKerningAndLigaturesEnabledByDefault UIKitUsesCoreUIArtwork hasAccessibilityBeenMigrated UIPreferredContentSizeCategoryName _UIConstraintBasedLayoutEngageNonLazily UIViewShowAlignmentRects NSTypesetterBehavior NSTypesetterCompatibilityLevel NSStringDrawingTypesetterBehavior NSTextShowsInvisibleCharacters NSTextShowsControlCharacters NSTextAllowsNonContiguousLayout NSTextBackgroundLayoutEnabled NSTighteningFactorForTruncation NSForceRightToLeftWritingDirection NSStringDrawingLongTermCacheSize NSStringDrawingLongTermThreshold NSStringDrawingShortTermCacheSize NSPreTigerAttributedStringHash _UIConstraintBasedLayout NSConstraintBasedLayoutShouldIntegralize _UIConstraintBasedLayoutPlaySoundWhenEngaged NSConstraintBasedLayoutDebug NSConstraintBasedLayoutDebugEngineConsistency NSConstraintBasedLayoutLogPivotCounts NSConstraintBasedLayoutDebugIntegralization
![Page 21: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/21.jpg)
UIDisableLegacyTextView WebKitKerningAndLigaturesEnabledByDefault UIKitUsesCoreUIArtwork hasAccessibilityBeenMigrated UIPreferredContentSizeCategoryName _UIConstraintBasedLayoutEngageNonLazily UIViewShowAlignmentRects NSTypesetterBehavior NSTypesetterCompatibilityLevel NSStringDrawingTypesetterBehavior NSTextShowsInvisibleCharacters NSTextShowsControlCharacters NSTextAllowsNonContiguousLayout NSTextBackgroundLayoutEnabled NSTighteningFactorForTruncation NSForceRightToLeftWritingDirection NSStringDrawingLongTermCacheSize NSStringDrawingLongTermThreshold NSStringDrawingShortTermCacheSize NSPreTigerAttributedStringHash _UIConstraintBasedLayout CUILogFPOArtwork WebKitSingleTapModeEnabled com.apple.uikit.textWebKitJavaEnabled WebKitJavaEnabled com.apple.uikit.textWebKitJavaScriptEnabled WebKitJavaScriptEnabled com.apple.uikit.textWebKitPluginsEnabled WebKitPluginsEnabled com.apple.uikit.textWebKitDatabasesEnabledPreferenceKey WebKitDatabasesEnabledPreferenceKey com.apple.uikit.textWebKitLocalStorageEnabledPreferenceKey WebKitLocalStorageEnabledPreferenceKey com.apple.uikit.textWebKitOfflineWebApplicationCacheEnabled WebKitOfflineWebApplicationCacheEnabled com.apple.uikit.textWebKitDiskImageCacheEnabled WebKitDiskImageCacheEnabled com.apple.uikit.textWebKitAcceleratedDrawingEnabled WebKitAcceleratedDrawingEnabled com.apple.uikit.textWebKitDefaultFontSize WebKitDefaultFontSize com.apple.uikit.textWebKitAlwaysUseBaselineOfPrimaryFontPreferenceKey WebKitAlwaysUseBaselineOfPrimaryFontPreferenceKey com.apple.uikit.textWebKitStandardFont WebKitStandardFont com.apple.uikit.textWebKitMinimumFontSize WebKitMinimumFontSize com.apple.uikit.textWebKitShowDebugBorders WebKitShowDebugBorders com.apple.uikit.textWebKitShowRepaintCounter WebKitShowRepaintCounter NSHTMLPrefixSpaces NSHTMLInterchangeNewline NSHTMLNoDefaultFonts NSHTMLTabsToSpaces NSHTMLCoalesceTabSpans NSHTMLTextEncodingName NSHTMLCharacterEncoding NSUndoManagerDefaultLevelsOfUndo WebKitLocalStorageDatabasePathPreferenceKey WebDatabaseDirectory WebKitStoreWebDataForBackup WebKitStorageTrackerEnabledPreferenceKey NSFileManagerRemoveUbiquitousItems WebKitLocalCache WebKitDiskImageCacheSavedCacheDirectory WebSmartInsertDeleteEnabled WebKitUseSiteSpecificSpoofing WebKitCursiveFont WebKitDefaultFixedFontSize WebKitDefaultTextEncodingName WebKitUsesEncodingDetector WebKitFantasyFont WebKitFixedFont WebKitScreenFontSubstitutionEnabled WebKitForceFTPDirectoryListings WebKitFTPDirectoryTemplatePath WebKitWebSecurityEnabled WebKitAllowUniversalAccessFromFileURLs WebKitAllowFileAccessFromFileURLs WebKitJavaScriptCanOpenWindowsAutomatically WebKitMinimumLogicalFontSize WebKitPictographFont WebKitPrivateBrowsingEnabled WebKitSansSerifFont WebKitSerifFont WebKitDisplayImagesKey WebKitLoadSiteIconsKey WebKitShrinksStandaloneImagesToFit WebKitEditableLinkBehavior WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey WebKitDOMPasteAllowedPreferenceKey WebKitUsesPageCachePreferenceKey WebKitPageCacheSupportsPluginsPreferenceKey WebKitBackForwardCacheExpirationIntervalKey DisableWebKitDeveloperExtras WebKitDeveloperExtras IncludeDebugMenu WebKitDeveloperExtrasEnabledPreferenceKey WebKitJavaScriptExperimentsEnabledPreferenceKey WebKitAuthorAndUserStylesEnabledPreferenceKey WebKitApplicationChromeModeEnabledPreferenceKey WebKitStandalonePreferenceKey WebKitMaximumImageSize WebKitTelephoneParsingEnabledPreferenceKey WebKitAllowMultiElementImplicitFormSubmissionPreferenceKey WebKitLayoutIntervalPreferenceKey WebKitMaxParseDurationPreferenceKey WebKitAlwaysUseAcceleratedOverflowScroll WebKitAllowCompositingLayerVisualDegradation WebKitWebArchiveDebugModeEnabledPreferenceKey WebKitLocalFileContentSniffingEnabledPreferenceKey WebKitJavaScriptCanAccessClipboard WebKitXSSAuditorEnabled WebKitDNSPrefetchingEnabled WebKitAcceleratedCompositingEnabled WebKitCanvasUsesAcceleratedDrawing WebKitAccelerated2dCanvasEnabled WebKitFrameFlatteningEnabled WebKitSpatialNavigationEnabled WebKitPaginateDuringLayoutEnabled WebKitCSSRegionsEnabled WebKitCSSCompositingEnabled WebKitWebAudioEnabled WebKitSeamlessIFramesEnabled WebKitCSSGridLayoutEnabled WebKitAsynchronousSpellCheckingEnabled WebKitHyperlinkAuditingEnabled WebKitUsePreHTML5ParserQuirks WebKitQTKitEnabled WebKitMediaPlaybackRequiresUserGesture WebKitMediaPlaybackAllowsInline WebKitMediaPlaybackAllowsAirPlay WebKitAudioSessionCategoryOverride WebKitNetworkDataUsageTrackingEnabledPreferenceKey WebKitNetworkInterfaceNamePreferenceKey WebKitSuppressesIncrementalRendering WebKitRegionBasedColumnsEnabled WebKitBackspaceKeyNavigationEnabled WebKitWantsBalancedSetDefersLoadingBehavior WebKitMockScrollbarsEnabled WebKitShouldDisplaySubtitles WebKitShouldDisplayCaptions WebKitShouldDisplayTextDescriptions WebKitShouldRespectImageOrientation WebKitRequestAnimationFrameEnabled WebKitUseLegacyTextAlignPositionedElementBehavior WebKitDiagnosticLoggingEnabled WebKitLowPowerVideoAudioBufferSizeEnabled WebKitStorageBlockingPolicy WebKitPlugInSnapshottingEnabled WebKitHiddenPageCSSAnimationSuspensionEnabled WebKitIncrementalRenderingSuppressionTimeoutInSeconds WebKitApplicationCacheDefaultOriginQuota WebKitZoomsTextOnly WebKitMinimumZoomFontSizePreferenceKey WebKitDiskImageCacheMinimumImageSize WebKitDiskImageCacheMaximumCacheSize WebKitInterpolationQualityPreferenceKey WebKitEnablePasswordEchoPreferenceKey WebKitPasswordEchoDurationPreferenceKey MapsFeatureFreedom DebugDynamicMapModesEnabledKey HideDirectionalArrowsKey UseOldLabelsKey AltitudeTelemetryURLKey HighlightUnmatchedRouteLineKey VKReadLandmarksFromDisk VKUseStaticTrafficFeed NSConstraintBasedLayoutShouldIntegralize _UIConstraintBasedLayoutPlaySoundWhenEngaged NSConstraintBasedLayoutDebug NSConstraintBasedLayoutDebugEngineConsistency NSConstraintBasedLayoutLogPivotCounts NSConstraintBasedLayoutDebugIntegralization _NSRaiseWithRecursiveLayoutRequest _NSAllowsScreenFontKerning NSGlyphGeneratorConcreteClassName NSDebugBidi NSCorrectionUnderlineBehavior NSUnderlinesBreakForDescenders PreferCFURLProtocol com.apple.uikit.textWebKitCacheModelPreferenceKey WebKitCacheModelPreferenceKey WebKitOmitPDFSupport DataDetectorsUILogLevel NSAllowContinuousSpellChecking CUIAllowDebugPrefs CUIRenditionBlockCacheCostLimit NSHTMLIndexing NSTextIndexing NSHTMLTesting NSUseLibXML2 NSRunWebKitOnAppKitThread __NSDisableSharingTextTabInstance NSRTFWriteOpenStepCompatibleEncodings NSRTFWritePreserveNaturalAlignment AppleLanguages
![Page 22: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/22.jpg)
Interesting Options
• DataDetectorsUILogLevel (integer)
• NSConstraintBasedLayoutDebug (boolean)
• NSTextShowsInvisibleCharacters (boolean)
• NSTextShowsControlCharacters (boolean)
• WebKitShowDebugBorders (boolean)
• WebKitShowRepaintCounter (boolean)
• WebKitDiagnosticLoggingEnabled (boolean)
![Page 23: Launch Arguments & NSUserDefaults by Franck Lefebvre](https://reader031.fdocuments.in/reader031/viewer/2022020207/556ea1dad8b42afe778b4809/html5/thumbnails/23.jpg)
References
• http://nshipster.com/launch-arguments-and-environment-variables/
• http://sssslide.com/speakerdeck.com/kishikawakatsumi/secrets-of-launch-arguments-ios
• http://oleb.net/blog/2014/02/nsuserdefaults-handling-default-values/
• Apple Tech Note 2239: iOS Debugging Magic
• WWDC 2013 session 219