Global Constants File in Swift: Best Practices
Hello everyone! I'm a beginner iOS developer in Swift, and I have a question about organizing constants in a project. Previously, I worked with Objective-C, where we often used a separate header file with #define for all global values. Now in Swift, I want to do something similar, but I'm not sure how to do it correctly.
Currently, I created a separate Constants.swift file and simply declare let variables at the file level:
```swift
let apiBaseURL = "https://api.example.com"
let defaultTimeout: TimeInterval = 30.0
let maxLoginAttempts = 3
let appName = "MyApp"
```
But this doesn't seem very clean to me. First, all these constants are in the global scope, and I'm afraid of name conflicts. Second, as the project grows, there are many constants, and they are difficult to group. Third,
No answers yet.
Log in to leave an answer