Sha256: d712220ad612b872db551d85691740e02c401a0732fde1395f33c909a65edcc2
Contents?: true
Size: 1.11 KB
Versions: 396
Compression:
Stored size: 1.11 KB
Contents
#import <Foundation/Foundation.h> #import "RobotNameExample.h" @implementation Robot - (instancetype)init { self = [super init]; if (self) { self.name = [self generateName]; } return self; } - (NSString *)generateName { return [NSString stringWithFormat:@"%@%@%@%@%@", [self randomCharacter],[self randomCharacter], [self randomDigit],[self randomDigit],[self randomDigit]]; } - (void)reset { self.name = [self generateName]; } - (NSString *)randomCharacter { return [self randomObjectFromArray:[self characters]]; } - (NSString *)randomDigit { return [self randomObjectFromArray:[self digits]]; } - (NSArray *)characters { return @[ @"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I", @"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z" ]; } - (NSArray *)digits { return @[ @"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9" ]; } - (NSString *)randomObjectFromArray:(NSArray *)array { long randomValue = random(); unsigned long randomCharacterIndex = randomValue % [array count]; return array[randomCharacterIndex]; } @end
Version data entries
396 entries across 396 versions & 1 rubygems