UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

5      

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.

5      

Thank you @NigelGee

5      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.