Skip to content

Commit ccef9e4

Browse files
committed
Merge branch 'deploy/0.3.0' into productive
2 parents 0a0732f + 89874ee commit ccef9e4

File tree

9 files changed

+85
-23
lines changed

9 files changed

+85
-23
lines changed

.projlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rules:
1010
SwiftLint: |
1111
if [ "${CONFIGURATION}" = "Debug" ]; then
1212
if which swiftlint > /dev/null; then
13-
swiftlint
13+
swiftlint --quiet
1414
else
1515
echo "warning: SwiftLint not installed, download it from https://github.com/realm/SwiftLint"
1616
fi

.swiftlint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ custom_rules:
176176
severity: warning
177177
controller_class_name_suffix:
178178
included: ".*.swift"
179-
regex: 'class +\w+(?<!View|Flow)Controller'
179+
regex: 'class +\w+(?<!View|Flow|Model|Presentation)Controller'
180180
name: "Controller Class Name Suffix"
181-
message: "Only use the `Controller` class name suffix for ViewControllers or FlowControllers."
181+
message: "Only use the `Controller` class name suffix for View-, Flow-, Model- and PresentationControllers."
182182
severity: warning
183183
debug_log_level:
184184
included: ".*.swift"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
55

66
## [Unreleased]
77

8+
## [0.3.0] - 2018-10-24
9+
### Added
10+
- Convenience `do` method on `MungoHealer` to simplify usage with single `handle(error)` catch-all.
11+
812
## [0.2.0] - 2018-10-24
913
### Added
1014
- Convenience implementations of error protocols: `MungoError`, `MungoFatalError` & `MungoHealableError`

Demos/MungoHealer iOS-Demo/MungoHealer iOS-Demo/ViewController.swift

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,32 @@ struct MyHealableError: HealableError {
4141

4242
class ViewController: UIViewController {
4343
@IBAction func throwErrorButtonPressed() {
44-
do {
44+
mungo.do {
4545
throw MyError()
46-
} catch {
47-
mungo.handle(error)
4846
}
4947
}
5048

5149
@IBAction func throwLocalizedErrorButtonPressed() {
52-
do {
50+
mungo.do {
5351
throw MyLocalizedError()
54-
} catch {
55-
mungo.handle(error)
5652
}
5753
}
5854

5955
@IBAction func throwBaseErrorButtonPressed() {
60-
do {
56+
mungo.do {
6157
throw MyBaseError()
62-
} catch {
63-
mungo.handle(error)
6458
}
6559
}
6660

6761
@IBAction func throwFatalErrorButtonPressed() {
68-
do {
62+
mungo.do {
6963
throw MyFatalError()
70-
} catch {
71-
mungo.handle(error)
7264
}
7365
}
7466

7567
@IBAction func throwHealableErrorButtonPressed() {
76-
do {
68+
mungo.do {
7769
throw MyHealableError(retryClosure: { [weak self] in self?.throwHealableErrorButtonPressed() })
78-
} catch {
79-
mungo.handle(error)
8070
}
8171
}
8272
}

Frameworks/MungoHealer/MungoHealer.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,15 @@ public class MungoHealer {
3838
errorHandler.handle(error: error)
3939
}
4040
}
41+
42+
/// Shorthand syntax for handling all errors using `mungo.handle(error)`.
43+
///
44+
/// - Parameter closure: The throwing code to be handled automatically if needed.
45+
public func `do`(_ closure: () throws -> Void) {
46+
do {
47+
try closure()
48+
} catch {
49+
handle(error)
50+
}
51+
}
4152
}

Frameworks/SupportingFiles/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.2.0</string>
18+
<string>0.3.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

MungoHealer.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "MungoHealer"
4-
s.version = "0.2.0"
4+
s.version = "0.3.0"
55
s.summary = "Error Handler based on localized & healable (recoverable) errors without the overhead of NSError. "
66

77
s.description = <<-DESC

MungoHealer.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
);
639639
runOnlyForDeploymentPostprocessing = 0;
640640
shellPath = /bin/sh;
641-
shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if which swiftlint > /dev/null; then\n swiftlint\n else\n echo \"warning: SwiftLint not installed, download it from https://github.com/realm/SwiftLint\"\n fi\nfi\n";
641+
shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if which swiftlint > /dev/null; then\n swiftlint --quiet\n else\n echo \"warning: SwiftLint not installed, download it from https://github.com/realm/SwiftLint\"\n fi\nfi\n";
642642
};
643643
A102BDD81F023D6C000C6B38 /* SwiftLint */ = {
644644
isa = PBXShellScriptBuildPhase;

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
alt="Build Status">
1010
</a>
1111
<a href="https://github.com/JamitLabs/MungoHealer/releases">
12-
<img src="https://img.shields.io/badge/Version-0.2.0-blue.svg"
13-
alt="Version: 0.2.0">
12+
<img src="https://img.shields.io/badge/Version-0.3.0-blue.svg"
13+
alt="Version: 0.3.0">
1414
</a>
1515
<img src="https://img.shields.io/badge/Swift-4.2-FFAC45.svg"
1616
alt="Swift: 4.2">
@@ -40,6 +40,53 @@ When developing a new feature for an App developers often need to both have pres
4040

4141
While there are many ways to deal with such situations, MungoHealer provides a straightforward and Swift-powered approach that uses system alerts for user feedback by default, but can be easily customized to use custom UI when needed.
4242

43+
## tl;dr
44+
45+
Here's a very simple example of basic error handling without MungoHealer:
46+
47+
```swift
48+
func login(success: (String) -> Void) {
49+
guard let username = usernameLabel.text, !username.isEmpty else {
50+
let alertCtrl = UIAlertController(title: "Invalid User Input", message: "Please enter a username.", preferredStyle: .alert)
51+
alertCtrl.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
52+
viewController.present(alertCtrl, animated: true, completion: nil)
53+
return
54+
}
55+
guard let password = passwordLabel.text, !password.isEmpty else {
56+
let alertCtrl = UIAlertController(title: "Invalid User Input", message: "Please enter a password.", preferredStyle: .alert)
57+
alertCtrl.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
58+
viewController.present(alertCtrl, animated: true, completion: nil)
59+
return
60+
}
61+
guard let apiToken = getApiToken(username, password) else {
62+
let alertCtrl = UIAlertController(title: "Invalid User Input", message: "Username and password did not match.", preferredStyle: .alert)
63+
alertCtrl.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
64+
viewController.present(alertCtrl, animated: true, completion: nil)
65+
return
66+
}
67+
success(apiToken)
68+
)
69+
```
70+
71+
Using MungoHealer the above code becomes this:
72+
73+
```swift
74+
func login(success: (String) -> Void) {
75+
mungo.do {
76+
guard let username = usernameLabel.text, !username.isEmpty else {
77+
throw MungoError(source: .invalidUserInput, message: "Please enter a username.")
78+
}
79+
guard let password = passwordLabel.text, !password.isEmpty else {
80+
throw MungoError(source: .invalidUserInput, message: "Please enter a password.")
81+
}
82+
guard let apiToken = getApiToken(username, password) else {
83+
throw MungoError(source: .invalidUserInput, message: "Username and password did not match.")
84+
}
85+
success(apiToken)
86+
}
87+
)
88+
```
89+
4390
## Installation
4491

4592
Installing via [Carthage](https://github.com/Carthage/Carthage#carthage) & [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) are both supported.
@@ -340,6 +387,16 @@ private func loadAvatarImage() {
340387

341388
We don't need to deal with error handling on the call side which makes our code both more readable & more fun to write. Instead, we define how to deal with the errors at the point where the error is thrown/defined. On top of that, the way errors are communicated to the user is abstracted away and can be changed App-wide by simply editing the error handler code. This also makes it possible to handle errors in the model or networking layer without referencing any `UIKit` classes.
342389

390+
For cases where you just want one catch-all where you just call the `handle(error)` method, there's even a shorthand which will deal with this automatically. Just use this instead of the above code:
391+
392+
```swift
393+
private func loadAvatarImage() {
394+
mungo.do {
395+
imageView.image = try fetchImage(urlPath: user.avatarUrlPath)
396+
}
397+
}
398+
```
399+
343400
So as you can see, used wisely, MungoHealer can help to make your code **cleaner**, **less error prone** and it can **improve the User Experience** for your users.
344401

345402
## Contributing

0 commit comments

Comments
 (0)