Learn Courses My Dashboard

14 Day Beginner Challenge (SwiftUI)

Questions relevant to Lesson 8 Challenge (structures)

The assignment calls to create 4 Properties and " Make all 4 properties have the private access level"

What is the difference between a regular and a private variable?
What is the purpose of this and are there any other access levels? Where can I find documentation to sort them out?

I also copied on my playground the solution to that challenge as found in the documentation. But I am unable to find a way to see the result on either of the right sidebar or on the bottom section. There isn’t any output that I can see the concatenation of my private variables. I can’t find a way to create a print line to make it visible either. What am I doing wrong?

Thank you for your help!

Hi Jocelyn,

Welcome to the Code Crew community.

When you declare a variable or a constant as private it means that it is not accessible from outside of the class or struct that it is defined within.

The Swift Programming Language is available on Apple Books:

To see the struct function in operation you need to do something like this in playground:

let myCar = Car()
print(myCar.getDetails())

That creates an instance of Car as myCar so then to access the function within the struct you specify the instance and then using dot notation access the function getDetails

Thank you for your reply! But I actually figured it out when I looked at the lesson 9 video. Nearly all my questions were answered with that video. I figured that the challenge following lesson 8 should actually be moved to the end of lesson 9 to practice and review the new material. Putting it at the end of lesson 8 confuses the student who is asked to use concepts that has not been seen yet…
I just wanted to suggest this for as not to confuse and discourage other students to follow through. I think the lessons are very clear and quite well broken down for an easy understanding. It is the best class to learn Swift I’ve seen so far.

4 Likes

Thanks, Joshembro. I was struggling with this too!

Hi All/Chris,

I am on the 14 day beginner challenge. Currently on lesson 7 challenge.
Not sure if info to complete the challenge or if I coding is even right, any help will be appreciated.

thanks

So, … where exactly are you struggeling?

Hi,

Lesson 7 challenge; Challenge 2.

This is what I have done, just wondering if it makes any sense?


func printTotalWithTax(subtotal :Double = 0, b: Double) -> Double {
    
    return subtotal*b
}

let mySum = printTotalWithTax(subtotal: 100, b: 1.13)
print(mySum)

Thanks


func printTotalWithTax(subtotal :Double = 0, b: Double) -> Double {
    
    return subtotal*b
}

let mySum = printTotalWithTax(subtotal: 100, b: 1.13)
print(mySum)