Skip to content

Instantly share code, notes, and snippets.

View AppleCEO's full-sized avatar
πŸ’»

도미닉 AppleCEO

πŸ’»
View GitHub Profile
enum Stage: String {
case production
case staging
case dev
case local
init?(rawValue: String) {
switch rawValue.lowercased() {
case "prod", "production": self = .production
case "qa", "staging": self = .staging
case "dev": self = .dev
enum Stage: String {
case production = "prod"
case staging
case dev
case local
}
let stage = Stage.production
let params = ["stage" : stage.rawValue] // ["stage": "prod"]
let stage = Stage.production
let params = ["stage" : stage.rawValue] // ["stage": "production"]
enum Stage: String {
case production
case staging
case dev
case local
}
enum Game {
case singlePlayer(SinglePlayerGame)
case multiPlayer(MultiPlayerGame)
case ai(AIGame)
}
let aiGame = ...
let game = Game.ai(aiGame)
struct SinglePlayerGame {
let id: String
let numOfPlayers: Int
let weaponsCollected: [String]
}
enum DateType {
case concrete(Date)
case range(Range<Date>)
}
let data: [Any] = [Date(), "string", 123]
for elem: Any in data {
switch elem {
case let stringVal as String: // handle string
case let intVal as Int: // handle integer
case let dateVal as Date: // handle date
default: // handle others
}
}
@AppleCEO
AppleCEO / logEvent.swift
Created August 20, 2025 06:26
logEvent
func logEvent(event: AnalyticsEvent) {
switch event {
case .sendFeedback(_: String, content: String):
print("\(content)")
// rest of the cases
}
if case let AnalyticsEvent.sendFeedback(_, content) = event {
print("\(content)")
}
@AppleCEO
AppleCEO / feedbackEvent.swift
Created August 20, 2025 06:24
feedbackEvent
let feedbackEvent = AnalyticsEvent.sendFeedback(userId: "id", content: "content")