NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

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 RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

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.