Skip to content

Latest commit

 

History

History
46 lines (42 loc) · 1.26 KB

README.org

File metadata and controls

46 lines (42 loc) · 1.26 KB

Dynamic Swift

Dynamically Typed Swift, Built on Regular Swift.

(Work in Progress, Not Ready for Production)

The Main Ideas:

Versatile Arrays

Support arrays with variadic arguments of mixed types, enabling the creation of flexible and dynamically typed collections.

let diverseArray = [1, "two", 3.5, (name: "Alex", age: 29)]

HashMap DataStructure on Named-Tuple Syntax

let person = (name: "Jordan", age: 35,
              interests: ["Hiking", "Photography"])

Function definations with Dynamic Type-Handling

func printArrayElements(array) {
    for element in array {
        switch element {
        case let int as Int:
            print("Int: \(int)")
        case let str as String:
            print("String: \(str)")
        case let tuple as (name: String, age: Int):
            print("Person: \(tuple.name), Age: \(tuple.age)")
        default:
            print("Unknown Type")
        }
    }
}

Function definations with Variadic Parameters

Accept an indefinite number of arguments

func combineElements(args...) {
    var combinedString = ""
    for arg in args {
        combinedString += "\(arg) "
    }
    print(combinedString)
}