Hello! I can't understand what am I supposed to do in this exercise. Can someone walk me through?
Exercise: Leap Years
To decide if a year is a leap year, there are several decisions that have to be made in the correct order.
Is the year divisible by 4?
If so, is the year divisible by 100?
If so, is the year divisible by 400?
If so, it is a leap year.
If not, it is not a leap year.
If it's not divisible by 100, it is a leap year.
If it's not divisible by 4, it is not a leap year.
These decisions can be made inside a function as a series of nested if...else statements.
The number(_:, isDivisibleBy:) function has been built into this playground to make this exercise easier. Below is an incomplete function for deciding if a given year is a leap year:
func isLeapYear(_ year: Int) -> Bool {
// Is the year divisible by 4?
if number(year, isDivisibleBy: 4) {
return true
} else {
return false
}
// Should be true
isLeapYear(2000)
// Should be false
isLeapYear(1900)
// Should be true
isLeapYear(2012)
// Should be false
isLeapYear(2017)
Exercise
Complete the function above so that the rules are all followed and the examples get the correct answers.
Hint: Try using the rules as pseudocode by making them into comments. Then write the code that goes with each comment underneath it.
Exercise
For a challenge, complete the function below. It should behave identically without using any nested conditional statements. Use a single level of if/else statements along with conditionals that use Boolean operators.
Hint: Create constants that represent the three key conditions, and then compose a Boolean expression with those constants.
func isLeapYear2(_ year: Int) -> Bool {
}
Post
Replies
Boosts
Views
Activity
Hello to everyone! I’m glad to be able to inform you that with Public Beta macOS 13.4 the issue seems to be fixed:)🎉🎉🎉 Have a great day!
If anyone there is familiar with Cocoa, can you please help with the following issue: How to make the NSWindow resize based on the contentView? Here is a video of the problem: https://drive.google.com/file/d/19LN98xdF9OLcqRZhMJsGGSa0dgMvj_za/view?usp=sharing
Thanks!
When making a custom System Settings panel, I want the project to automatically move the prefpane file to /Library/PreferencePanes/. With Run Script, the build fails because of denial to perform the operation. Sudo doesn't help, too.
PREFPANE_SRC="${BUILT_PRODUCTS_DIR}/App.prefPane"
PREFPANE_DST="$HOME/Library/PreferencePanes/"
echo "PrefPane source path: $PREFPANE_SRC"
echo "PrefPane destination path: $PREFPANE_DST"
if [ -d "$PREFPANE_SRC" ]; then
echo "Installing preference pane to ${PREFPANE_DST}"
cp -R "${PREFPANE_SRC}" "${PREFPANE_DST}"
else
echo "Preference pane not found: ${PREFPANE_SRC}"
exit 1
fi
Hello! I’m making an app which will have a waveform of the frequency of what’s playing on a Mac. The question is whether it is possible to have access to the signal of the media and use it with the FFT?