Group Group Group Group Group Group Group Group Group

Text.background accepting Color is not very intuitive

I am going through https://www.raywenderlich.com/4001741-swiftui/lessons/4 and was stuck on Text.background where in video the backcolor was changed to Color.gray.

Just out of curiosity I tried to check the documentation of Text.background method but could not spot it in documentation. Then I found it in View.background.

But in View.background there was no parameter which takes Color as input. On further digging I found that input is Background which is of type View and Color has been extended to implement View.

All in all I was able to put all piece together but that was because instructor had written Text.background(Color.gray) but otherwise since I am a starter so it is not very easy to deduce that Text.background could even take Color as parameter.

Is there any suggestion for newbies to handle such situation because otherwise I can’t imagine I would have passed Color to background had I followed the documentation only.

Thanks,
Ishwar Jindal

Hi @ishwar_jindal, welcome to the forum community! I can definitely relate to you in regards to being new with Swift and not really knowing the full capabilities the language has. Especially when it comes to the class UIView. My only suggestion would to continue coding and learning! With practice or even experimentation, you can learn something new. Not only will it build upon your overall knowledge base but it will also give you the confidence to try something that may or may not work. From my personal experience I’ve learned mostly from others. The Ray Wenderlich site is a great example and once I felt more confident I started to use the Apple documentation to narrow down any questions I might have in regards to what a class can do, frameworks, etc.

Best,
Gina