Question: You are going to use an enum we previously worked with ( Month ) to implement a CalendarView struct that conforms to the tableDataSource protocol
You are going to use an enum we previously worked with Month to implement a CalendarView struct that conforms to the tableDataSource protocol shown in class. You will implement the methods of the protocol and check to make sure that they work correctly. Then you will also implement the CustomStringConvertible protocol so that the CalendarView will print an accurate view of a specific Months calendar to the Console.
Directions:
Creating a CalendarView Struct
Add a new Swift File to the program named CalendarView
Create a new Type in the file named CalendarView that implements the tableDataSource protocol.
Add the following instance properties to the CalendarView:
var currentMonth: Month
represents the month being used to print the calendar defined in Month.Swift A Month has methods for returning its number of days and other pertinent data.
var leap: Bool
represents whether or not this is a leap year. Really only relevant when printing february.
var startingDay: Weekday
the starting day for the month. A Weekday is an enum that has a raw Int value. Knowing this is important to drawing the Calendar correctly.
Add the required properties and methods for the protocol conformance for tableDataSource
numberOfColumns should return
numberOfRows should return we will need this many to accommodate a realistic looking calendar
labelforColumn column: Int String should return a label for each day of the week using the first letters of each day, EGSun or Fri See the following page for an example of output.
func itemForrow: Int, column: Int String should return the numerical date EG or for the given row and column. Note: there is an arithmetic formula that will correctly calculate the date, knowing the starting position in Week which corresponds to a Weekdays raw value If the given row and column does not fall within the Months range of dates either before the st or after the last day this should return XX
Make a few CalendarView objects and check the methods youve defined to ensure they are working correctly. You may want to look at an actual Monthly calendar for this double checking your work
Printing a CalendarView:
Now we want to be able to print the CalendarViews. Add protocol conformance for the CustomStringConvertible protocol:
First list it at the top of the CalendarView Struct, next to the tableDataSource listing, separated by a comma.
Now define a public, computed String variable named description. This variable should return a labeled Calendar drawn in ASCII characters. This should utilize both the label and the itemFor methods youve already defined for tableDataSource Conformance.
Example of what the code should produce is pictured.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
