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 {}
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 .