Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Closures in Swift First Class Functions Higher Order Functions

Olivier Van hamme
Olivier Van hamme
5,418 Points

Outdated error message : String does not conform to Sequence protocol .

This code works in my Xcode Playground . However , Treehouse does not accept this code . Their error message says that String — referring to oldString in my for loop — does not conform to the Sequence type . This is incorrect because — as of 2019 — String automatically conforms to the Sequence protocol . You can try this out by looping through a String — e.g. "hello world" — and printing out every character .

functions.swift
// Enter your code below

extension String {
    func transform(_ operation: (String) -> String) -> String { 
        return operation(self) 
    } // END func transform(_ operation: (String) -> String) -> String {}
} // END extension String {}


func removeVowels(from oldString: String) -> String {
    var newString: String = ""

    for character in oldString {
        switch character {
        case "a" , "e" , "i" , "o" , "u" : break
        case "A" , "E" , "I" , "O" , "U" : break
        default : newString.append(character)
        } // END switch character {}
    } // END for character in oldString {}

    return newString
} // END func removeVowels(from oldString: String) -> String {}

1 Answer

Olivier Van hamme
Olivier Van hamme
5,418 Points

RESOLVED : Adding the depreciated .characters property to oldString — in my for loop — throws me an error in my Playground , but it has given me a pass over here , in the Treehouse code editor .