UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Beginning of my Journey - 100 Days of SwiftUi

Forums > 100 Days of SwiftUI

Good Afternoon All,

I just completed my first day of this journey and let me tell you I am pumped and excited, as I start to see the inner workings of the Swift Platform I am starting to see all the posiabilities and ways that I can make my overall goals come to life... I look forward to building on my new found understanding of constants, variables, and the various data types learned in day 1

I want to send a shout out to Paul and say thank you for sharing your knowledge, understanding and experince of the Swisft platform I look forward to learning from you and the other members of the forum.

3      

Good Afternoon,

Following Paul's guidance of post your progress to a social media site, I figure I would use this site to post my progress and share some of my findings.

I found that Day 2 was fantastic for building a foundation and deepening my general overall knowledge. As a visual learner, I found the short companion videos very useful in understanding new material. By applying previously learned lessons to more recent material, I feel I am reinforcing that information.

I have attached a snippet of code I used to help me understand "Sets" and understand how I could use the function of a "Set" in my code. (For me personally, by applying this to something that is a standard function in coding, I can then understand the potential of how I can use " Sets" I know everyone is different, but maybe this will help someone understand this better)

// Code Block - Testing an IF Statement using the contents of a Set for the evaluation condition

// variables and constants section

let colors = Set (["red", "Green", "Blue"]) var playerScore = 0

// If Statement

if colors.contains("Yellow") { print("This is true") playerScore += 10 }else { print("This is not true") playerScore += -10 }

// Final Action - In this case printing the results of the players score.

print(playerScore)

Since a "SET" does not have any specific order or location, I wanted to understand how I could use the values in a "Set" with practical coding logic. To see this in practice, I used an "IF" statement that would check the contents of the "Set," and if the condition statement equal to the contents information, then it would execute the If statement as "true"; otherwise, it would complete the statement as "false."

Although the context around using a PlayerScore might not be relevant, I wanted to see if the code's mechanics would work.

2      

Welcome to your journey, I hope that you enjoy it.

When posting code examples if you use the marker </> from the toolbar above, you can then embed the code between the ellipses and change the layout, it will look much better and be easier to follow, like so

// Code Block - Testing an IF Statement using the contents of a Set for the evaluation condition
// variables and constants section

let colors = Set (["red", "Green", "Blue"])
var playerScore = 0

// If Statement

if colors.contains("Yellow") {
   print("This is true") playerScore += 10
} else {
   print("This is not true") playerScore += -10 
}

// Final Action - In this case printing the results of the players score.

print(playerScore)

The other important feature about sets, other than not caring about the order, is that repeating an element does not increase the cardinality of the set. Try this.

let colors2 = Set (["red", "Green", "Blue", "Red", "red", "Blue", "red"])

print(colors2)
print(colors2.sorted())
print(colors2.count)

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.