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.180 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/robot-name/RobotNameExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/robot-name/RobotNameExample.m