🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of KiligWY

KiligWY's solution

to Acronym in the Objective-C Track

Published at Jul 13 2018 · 0 comments
Test suite

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).


There are two different methods of getting set up to run the tests with Objective-C:

  • Create an Xcode project with a test target which will run the tests.
  • Use the ruby gem objc as a test runner utility.

Both are described in more detail here: http://exercism.io/languages/objective-c

Submitting Exercises

When submitting an exercise, make sure your solution file is in the same directory as the test code.

The submit command will look something like:

exercism submit <path-to-exercism-workspace>/objective-c/acronym/Acronym.m

You can find the Exercism workspace by running exercism debug and looking for the line beginning with Workspace.


Julien Vanier https://github.com/monkbroc

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


#import <XCTest/XCTest.h>

#if __has_include("AcronymExample.h")
# import "AcronymExample.h"
# else
# import "Acronym.h"

@interface AcronymTest : XCTestCase


@implementation AcronymTest

- (void)testAcronymAbbreviateTest1 {
    XCTAssertEqualObjects(@"PNG", [Acronym abbreviate:@"Portable Network Graphics"]);

- (void)testAcronymAbbreviateTest2 {
    XCTAssertEqualObjects(@"ROR", [Acronym abbreviate:@"Ruby on Rails"]);

- (void)testAcronymAbbreviateTest3 {
    XCTAssertEqualObjects(@"HTML", [Acronym abbreviate:@"HyperText Markup Language"]);

- (void)testAcronymAbbreviateTest4 {
    XCTAssertEqualObjects(@"FIFO", [Acronym abbreviate:@"First In, First Out"]);

- (void)testAcronymAbbreviateTest5 {
    XCTAssertEqualObjects(@"PHP", [Acronym abbreviate:@"PHP: Hypertext Preprocessor"]);

- (void)testAcronymAbbreviateTest6 {
    XCTAssertEqualObjects(@"CMOS", [Acronym abbreviate:@"Complementary metal-oxide semiconductor"]);



#import <Foundation/Foundation.h>

@interface Acronym : NSObject

+ (NSString *)abbreviate:(NSString *)input;



#import "Acronym.h"

@implementation Acronym

+ (NSString *)abbreviate:(NSString *)input {
    input = [input stringByReplacingOccurrencesOfString:@"[^a-zA-Z ]" withString:@" " options:NSRegularExpressionSearch range:NSMakeRange(0, input.length)];
    __block NSString *result = @"";
    [input enumerateSubstringsInRange:NSMakeRange(0, input.length) options:NSStringEnumerationByWords usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
        result = [result stringByAppendingString:[[substring substringToIndex:1] uppercaseString]];
        for (NSInteger i = 1; i < substring.length; ++i) {
            NSString *subStr = [substring substringWithRange:NSMakeRange(i, 1)];
            NSString *subStr2 = [substring substringWithRange:NSMakeRange(i - 1, 1)];
            if ([subStr isEqualToString:[subStr uppercaseString]]
                && [subStr2 isEqualToString:[subStr2 lowercaseString]]) {
                result = [result stringByAppendingString:subStr];
    return result;


Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?