Apple's SwiftUI tutorial code doesn't display view contents in homemade copy
Solution 1:
I downloaded the project file from the tutorial, and I found there's a file that you probably missed. You can check the Models folder in the sample code, there's a file called Color+Codable.swift
which is responsible for this accessibleFontColor
thingy.
Solution 2:
Understand the issue
-
scrum.color.accessibleFontColor
applied to theforegroundColor
of the card. So all labels and images and texts and etc. will be affected. -
accessibleFontColor
seems to return eitherblack
orwhite
according to the parent color (scrum.color
in this case) -
seems
Color("Design")
that you are passing for the preview is returningclear
color because there is no color with the nameDesign
in assets in the starting project. So the preview shows the default white color as the card background. But it also uses thewhite
color for the foreground. So you see a solid white card in the result.
Solutions
-
Comment out the
.foregroundColor(scrum.color.accessibleFontColor)
-
Or add an assets color and name it as expected.
-
Or give the card a manual background
-
Or download the completed version and reverse the process to the point that you are at.
Solution 3:
This is caused by undefined "Design" color.
Copy the "Design" color from Assets.xcassets
from Apple's sample project, and put the color's definition under the Assets.xcassets
directory of your project can solve your problem.
Solution 4:
I ran into the same problem and found that I missed Step 5 in the "Creating a Card View -> Section 1: Create a Color Theme" part of the tutorial
I don't think the instructions in this step very clear here for someone not familiar with Xcode. I solved this by importing the resources from a downloaded version of the sample project. Try these steps
- Open the Assets file in Xcode
- Right click and select Import
- Navigate to the downloaded project and select the "Themes" directory, which is a subdirectory of Assets.xcassets
Your Assets file should look like this when you're finished. As a bonus you can use these same steps to import the app icon.