Minor Bugs and How to Fix it Swift Part I

Jerry PM
3 min readNov 10, 2022

here are some small bugs

Photo by Ritchie Valens on Unsplash

Maybe you’ve come across some bugs like this, which often happens because of wrong coding

1. ErrorCode: Type ‘yourEnum’ has no member ‘allCases’

Source: Author

The solution is to use CaseIterable that automatically generates an array property of all cases in an enum

// Error Codeenum ListSection: Int {
case registered = 0
case login = 1
case biometric = 2
}
print(ListSection.allCases.count) // error here// Solutionenum ListSection: Int, CaseIterable {
case registered = 0
case login = 1
case biomatric = 2
}
print(ListSection.allCases.count) // 3

2. initializer without initializing all stored properties

Source: Author

I try to change a property from let to var but still not working and get this error “Return from initializer without initializing all stored properties”. I tried to check the comparison with other `init` but couldn’t find a solution. I’m trying to find out again. What is wrong, finally I found the error because the variable “accountEmail” and “accountName” if you create “init “ you need to give an optional value to a variable not to call in “init”.

Source: Author

3. Error: validation failed: Couldn’t parse property list because the input data was in an invalid format

Source: Author

When create a Localizable. strings file and found this error on the top file, I don’t know where the error is, so you can try this for how to know where the error.
- Right-click the strings file and
- Then Open as/ASCII property list.

Source: Author

After you click that popup will show where the error line and what makes an error on this page, and then a popup will show like this.

Source: Author

4. Type of expression is ambiguous without more context

I get some error when write code like this

userWorker.getUserProfile(username: username) { [weak self] result in // error in here
.
.
.
}

to solve that error just remove `weak`

userWorker.getUserProfile(username: username) { [self] result in
.
.
.
}

Conclusion

I hope this article has been of help to you. practice, and improve your skills. Make you better developers.

Become a better developer with my templates. Your support by purchasing one of my templates would be greatly appreciated. Thank you.

My Swift UI news app template has been sold on the CodeCanyon website.
https://codecanyon.net/item/news-feed-app-using-swiftui/43068768 😄

--

--