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

Version Path
trackler-2.2.1.119 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.118 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.117 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.116 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.115 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.114 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.113 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.111 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.110 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.109 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.108 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.107 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.106 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.105 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.104 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.103 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.102 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.101 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.100 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.99 tracks/objective-c/exercises/robot-name/RobotNameExample.m