{"id":22787216,"url":"https://github.com/mancongios/mcnetwork","last_synced_at":"2025-03-30T16:16:33.596Z","repository":{"id":201763886,"uuid":"141267360","full_name":"mancongiOS/MCNetwork","owner":"mancongiOS","description":"封装的网络请求","archived":false,"fork":false,"pushed_at":"2018-07-17T10:20:25.000Z","size":123,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T17:41:45.189Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mancongiOS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-07-17T09:37:15.000Z","updated_at":"2018-08-03T08:10:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"48be12cb-3801-408b-be92-2c1c2f96e4cb","html_url":"https://github.com/mancongiOS/MCNetwork","commit_stats":null,"previous_names":["mancongios/mcnetwork"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancongiOS%2FMCNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancongiOS%2FMCNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancongiOS%2FMCNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mancongiOS%2FMCNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mancongiOS","download_url":"https://codeload.github.com/mancongiOS/MCNetwork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246342994,"owners_count":20761947,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-12T00:50:48.796Z","updated_at":"2025-03-30T16:16:33.575Z","avatar_url":"https://github.com/mancongiOS.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCNetwork\n封装的网络请求\n\n### 一. 代码下载地址\n[代码地址](https://github.com/mancongiOS/MCNetwork.git)\n\n### 二. MCNetwork说明\n*  集成了Alamofire和SwiftyJSON。请自行下载。\n*  对错误的处理\n\n```\nenum MCError \u003cT\u003e {\ncase codeError(T)             // 异常的结果处理\ncase networkNull             // 网络异常 没访问到服务器\ncase networkBadReturn        // 异常的数据结构\n}\n```\n* 调用方法的说明\n```\npublic static func POST(_ url: String!, _ params:[String:Any]? = [String:Any](), _ queue:DispatchQueue? = nil,success: @escaping Success\u003cJSON\u003e, failure: Failure\u003cMCError\u003cMCErrorDetail\u003e\u003e? = nil) -\u003e DataRequest { }\n```\n大部分情况下，只需要处理，理想返回的状态数据。所以单独用一个success闭包，传递出来JSON对象，外部不再需要考虑条件，直接处理数据即可。\n\n有一些情况下需要处理，错误的服务器code返回情况，比如登录异常。把它集成在MCError这个枚举中。codeError这个case对应的是一个结构体，有两个属性code，和message\n\n### 三. 使用\n```\nlet url = \"\"\nlet params = [  \"\":\"\"]\n\n// 只处理成功的网络请求\nMCNetwork.POST(url,params,success: { (data) in\n// data为JSON类型。 注意SwiftyJSON的使用\n})\n\n// 处理非成功的网络请求。\nMCNetwork.POST(url, [\"\":\"\"], nil, success: { (data) in\n\n}) { (error) in\n\nswitch error {\ncase .codeError(let codeError):\nweakSelf?.showLabel.text = \"\\(codeError.message) + \\(codeError.code)\"\ncase .networkNull:\nweakSelf?.showLabel.text = \"networkNull\"\ncase .wrongReturn:\nweakSelf?.showLabel.text = \"wrongReturn\"\n}\n}\n\n// GET请求\nMCNetwork.GET(url, params, nil, success: { (data) in\n\n}) { (error) in\n\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmancongios%2Fmcnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmancongios%2Fmcnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmancongios%2Fmcnetwork/lists"}