iOS 获取默认值

示例

要在NSUserDefaults中获取值,可以使用以下功能:

迅速

arrayForKey(_:)

boolForKey(_:)

dataForKey(_:)

dictionaryForKey(_:)

floatForKey(_:)

integerForKey(_:)

objectForKey(_:)

stringArrayForKey(_:)

stringForKey(_:)

doubleForKey(_:)

URLForKey(_:)

目标C

-(nullable NSArray *)arrayForKey:(nonnull NSString *)defaultName;

-(BOOL)boolForKey:(nonnull NSString *)defaultName;

-(nullable NSData *)dataForKey:(nonnull NSString *)defaultName;

-(nullable NSDictionary<NSString *, id> *)dictionaryForKey:(nonnull NSString *)defaultName;

-(float)floatForKey:(nonnull NSString *)defaultName;

-(NSInteger)integerForKey:(nonnull NSString *)defaultName;

-(nullable id)objectForKey:(nonnull NSString *)key;

-(nullable NSArray<NSString *> *)stringArrayForKey:(nonnull NSString *)defaultName;

-(nullable NSString *)stringForKey:(nonnull NSString *)defaultName;

-(double)doubleForKey:(nonnull NSString *)defaultName;

-(nullable NSURL *)URLForKey:(nonnull NSString *)defaultName;

用法示例为:

迅速

let homeCountry = NSUserDefaults.standardUserDefaults().stringForKey("HomeCountry")

目标C

NSString *homeCountry = [[NSUserDefaults standardUserDefaults] stringForKey:@"HomeCountry"];

           

以上是 iOS 获取默认值 的全部内容, 来源链接: utcz.com/z/315787.html

回到顶部