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

Luigi Santos
Luigi Santos
13,200 Points

How can I make this work?

This gives me no errors or warning in the playground. What am I doing wrong?

functions.swift
// Enter your code below
extension String {
  func transform(_ function: (String) -> String) -> String {
    return function(self)
  }
}

extension Character {
    var isVowel: Bool {
        let vowels: [Character] = ["a", "e", "i", "o", "u"]
        return vowels.contains(self)
    }
}

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

    for char in string.characters {
      if char.isVowel {

      } else {
        newString += String(char)
      }
    }

    return newString
  }

let result = String.transform(removeVowels(from: "Hello, World!"))

1 Answer

Luigi Santos
Luigi Santos
13,200 Points

Never mind, got it to work. Just thought it looked strange.

let result = "Hello, World".transform(removeVowels(from: ))