Member-only story
Logger (Debug)
5 min readJan 21, 2025
The Problems
As an iOS developer, I face this problem a lot. Poor quality of code appears in the following ways
// 1. ELSE not implemented
if my_condition {
do_stuff()
}// 2. ELSE not implemented when IF LET FAILS
if let sweet_optional = self.sweetOptional else {
do_stuff()
}// 3. Missing event log when GUARD LET FAILS
guard let sweet_optional = self.sweetOptional else {
return
}// 4. Missing DEFAULT log when NOT MATCH IN SWITCHswitch validityStatus {
case .valid:
do_valid_stuff()
case .invalid:
do_invalid_stuff()
default:
()
}
From senior developer’s perspective it’s a offense as these example codes are error prone. Only God can help you when you are debugging an error on the last night of your project’s deadline.
The Solution:
Once you start believing that you should handle these scenarios, you might be thinking to rewrite the codes in the following ways using print() or debugPrint()
// 1. ELSE not implemented
if my_condition {
do_stuff()
} else {
print("‼️OMG: my_condition failed")
}// 2. ELSE not implemented when IF LET FAILS
if let sweet_optional = self.sweetOptional else {
do_stuff()
} else {
print("⚠️OMG: self.sweetOptional is nil")
}// 3. Missing event log when GUARD LET FAILS
guard let sweet_optional = self.sweetOptional else {
debugPrint("⚠️OMG: self.sweetOptional is nil")
return
}// 4. Missing DEFAULT log when NO MATCH IN SWITCH
switch validityStatus {
case .valid…