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 Build a Selfie App with Swift 2 Adding Image Filters Adding Photo Filters

Having trouble in the Terminal app trying to return the CIFilter array.

Trying to return CIFilter array in Terminal.

Entering "CIFilter.filterNamesInCategory(nil).count" does not work in the updated Terminal for Swift 3. The app states that:

error: 'filterNamesInCategory' has been renamed to 'filterNames(inCategory:)'

Tried different permutations to pass in nil to get the count but must be doing something wrong. Anyone have ideas on how to refactor this to get the array(count)?

3 Answers

Swift 3 introduces a number of changes including small (but breaking) function call changes. Apple has done this in an effort to remove redundancy and retain clarity for what the intended purpose is. Essentially, what the error is outpointing to you is letting you know that, that particular function is one of the many that have been simplified. The error is telling you what you need to do to update your code statement to get the desired result.

So instead of Swift 2's:

CIFilter.filterNamesInCategory(nil).count

You will want to try:

CIFilter.filterNames(inCategory: nil).count

As I mentioned there are many small but breaking changes involved in Swift 3, so head over to the Swift Migration Page and take see what else you should be weary of in using Swift 3.

Hope that helps, good luck!

I also want to mention that, Xcode 8 should allow you to use Swift 2.3, which may be more beneficial when following the Swift 2 courses. Most all of the things learned in the Swift 2 course should still apply logically to Swift 3, there may just be variances in the method calls themselves and some other contextual changes. It seems Treehouse is looking to add Swift 3 courses as they complete them!

Thanks for your response, Joe.

Yeah, I tried

CIFilter.filterNames(inCategory: nil).count

and about a dozen other variations on the same theme. None returned a result. For that one, the error read:

error: repl.swift:2:1: error: type 'CIFilter' has no member 'filter'

but I just tried it again and got

-bash: syntax error near unexpected token `inCategory:'

Strange...

Have you imported CoreImage in the terminal?

Give this a shot first:

import CoreImage

If not you could get various errors. I am thinking the second error may be due to you being kicked out of the Swift REPL or bash just failing to continue to parse your entry after it REPL threw it's error.

Syntax error above may be a result of not having been in Swift "repl" in Terminal. Forgot that I had re-booted computer. Tried solution you offered above one more time after activating Swift "repl" in Terminal and importing coreImage. This time the error read:

repl.swift:1:1: error: use of unresolved identifier 'CIFilter'.

I figured as such, when I wrote my previous comment, I had not refreshed the page, so I missed this post.