NEW: Learn to build the incredible iOS 15 Weather app today! >>

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 Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

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

Reply to this topic…

You need to create an account or log in to reply.

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.