confused about optional chaining and nil coalescing operator in Swift

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


confused about optional chaining and nil coalescing operator in Swift



I'm having difficulty understanding the exercise below:



Assume the following structs and enum are defined.



enum Genre: String {
case country, blues, folk
}



struct Artist {
let name: String
var primaryGenre: Genre?
}



struct Song {
let title: String
let released: Int
var artist: Artist?
}



Using the enums and structures, implement the getArtistGenre() function. Given a Song as input, return the raw value of the artist's primary genre. If either the artist is nil or the primaryGenre is nil, then return an empty string. You must use optional chaining and the nil coalescing operator (??).



enum Genre: String {
case country, blues, folk
}



struct Artist {
let name: String
var primaryGenre: Genre?
}



struct Song {
let title: String
let released: Int
var artist: Artist?
}



func getArtistGenre(song: Song) -> String {



}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived