WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: UltimatePortfolio Asset Tests

Forums > Articles

I've just completed the first video on testing in Ultimate Portfolio. About the first testing method:

func testColoursExist() {
    for colour in Project.colours {
        XCTAssertNotNil(UIColor(named: colour), "Failed to load colour '\(colour)' from Asset Catalog.")

I understand that the expected names of colours come from the array of colour names in the Project extension (Project-CoreDataHelpers file) but what exactly is happening that means this function knows to cross check these colour names with the colours asset catalog?

Thank you.


When it loops though the array of colors (which are Strings) it puts the color in UIColor(named: String) and if this return a nil in other words there is no color string name in the Asset Catalog.

If you want to see it change add a other color to the array and run the test and it should fail.


Thank you @NigelGee


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.