Bracket Syntax for Structs and Classes?

Can bracket notation be used to access properties and or methods (of class and struct instances) instead of using dot syntax? Mainly, I’m trying to figure out a way to use a variable placeholder to access different properties.

For example, would the following code work in Swift? …

struct Person {
   var firstName = "" 
   var lastName = "" 
   var age = 0
} 

var drew = Person() 

drew["firstName"] = "Drew" 

Hello! It appears you can’t use bracket notation, as both structs and classes create a new type of object (in your case, the Person object), and therefore it doesn’t make much sense to add new properties to an object; imagine if you could locally change how Strings interacted-that too doesn’t make much sense. This article gives quite a good rundown of this.