Blobfish 1.0.1

Blobfish 1.0.1

Nodes Agency 维护。



Blobfish 1.0.1

  Blobfish

轻松处理错误并以优雅的方式展示给用户。

Carthage Compatible Plaform GitHub license

📦安装

Carthage

github "nodes-ios/Blobfish" ~> 1.0

与较低版本的 Swift 兼容的最新版本

Swift 2.3
github "nodes-ios/Blobfish" == 0.2.0

Swift 2.2
github "nodes-ios/Blobfish" == 0.1.2

🔧设置

Blob & Blobbable

待办:添加说明

Alamofire 扩展

在 AppDelegate 的 applicationDidFinishLaunching:launchOptions: 函数中首先进行 Blobfish 的基本设置

Blobfish.AlamofireConfig.blobForTokenExpired = {
    let action = Blob.AlertAction(title: "Ok", handler: {
        // Your custom actions on token expired go here
    })
    return Blob(title: "Token Expired", 
    			style: .Alert(message: "Your token has expired. Please log in again.", actions: [action]))
}

Blobfish.AlamofireConfig.blobForUnknownError = { _, _ in
    let action = Blob.AlertAction(title: "Ok", handler: nil)
    return Blob(title: "Uknown Error", 
    			style: .Alert(message: "Unknown error happened, please try again.", actions: [action]))
}

Blobfish.AlamofireConfig.blobForConnectionError = { _ in
    return Blob(title: "Connection error, please try again.", style: .Overlay)
}

有一个 Alamofire Response 扩展使其符合 Blobbable 协议,因此处理回调中的错误将变得很简单。

func doSomeRequest(completion: Response<AnyObject, NSError> -> Void) { ... }
// ...
doSomeRequest(completion: { response in 
	switch response.result {
	case .Failure(_):
		// First, handle your custom error codes manually
		if response.response?.statusCode == 870 {
			// Your code to handle a custom error code
		} else {
			// Fallback to Blobfish
			Blobfish.sharedInstance.handle(response)
		}
	default: break
})

👥致谢

❤️Nodes 上制作。

📄许可

Blobfish 经过 MIT 许可。有关更多信息,请参阅 LICENSE 文件。