\u8ba9\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u64cd\u4f5c\u7b26\u91cd\u8f7d\u6765\u89e3\u51b3\u4e0a\u8ff0\u95ee\u9898\u3002\u4f7f\u7528\u5927\u591a\u6570\u8bed\u8a00(\u5305\u62ecSwift)\u7684\u64cd\u4f5c\u7b26\u65f6\uff0c\u60a8\u6709\u90fd\u6709\u4e24\u4e2a\u9009\u9879\uff0c\u91cd\u8f7d\u73b0\u6709\u8fd0\u7b97\u7b26\uff0c\u6216\u8005\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8fd0\u7b97\u7b26\u3002\u91cd\u8f7d\u5de5\u4f5c\u5c31\u50cf\u65b9\u6cd5\u91cd\u8f7d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u65b0\u7684\u8f93\u5165\u6216\u8f93\u51fa\u521b\u5efa\u65b0\u7248\u672c\u7684\u64cd\u4f5c\u7b26\u3002<\/p>\n
\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u5b9a\u4e49-=\u8fd0\u7b97\u7b26\u7684\u8fc7\u8f7d\uff0c\u5b83\u4eec\u9002\u7528\u4e8e\u4e24\u4e2a Resources \u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\nextension Resources { \r\n static func -=(lhs: inout Resources, rhs: Resources) { \r\n lhs.gold -= rhs.gold \r\n lhs.wood -= rhs.wood \r\n } \r\n}\r\n<\/pre>\n\u5c31\u50cf\u9075\u5b88 Equatable \u534f\u8bae\u7684\u65f6\u5019\u4e00\u6837\uff0cSwift \u4e2d\u7684\u64cd\u4f5c\u7b26\u91cd\u8f7d\u53ea\u662f\u53ef\u4ee5\u5728\u7c7b\u578b\u4e0a\u58f0\u660e\u7684\u4e00\u4e2a\u6b63\u5e38\u9759\u6001\u51fd\u6570\u3002\u5728\u6b64\u5904 -= \u4e2d\uff0c\u64cd\u4f5c\u7b26\u7684\u5de6\u4fa7\u662f\u4e00\u4e2a inoiut \u53c2\u6570\uff0c\u8fd9\u662f\u6211\u4eec\u8981\u4fee\u6539\u7684\u503c\u3002<\/p>\n
\u901a\u8fc7\u6211\u4eec\u7684\u64cd\u4f5c\u7b26\u91cd\u8f7d\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u76f4\u63a5\u5728\u5f53\u524d\u7684\u73a9\u5bb6\u7684\u8d44\u6e90\u4e0a\u7b80\u5355\u5730\u8c03\u7528 -= \uff0c\u5c31\u50cf\u6211\u4eec\u5c06\u5176\u653e\u5728\u5728\u4efb\u4f55\u539f\u59cb\u6570\u503c\u4e0a\uff1a<\/p>\n
currentPlayer.resources -= kind.cost<\/pre>\n\u8fd9\u4e0d\u4ec5\u5f88\u597d\u9605\u8bfb\uff0c\u5b83\u8fd8\u6709\u52a9\u4e8e\u6211\u4eec\u6d88\u9664\u4ee3\u7801\u91cd\u590d\u95ee\u9898\u3002\u7531\u4e8e\u6211\u4eec\u603b\u662f\u5e0c\u671b\u6240\u6709\u5916\u90e8\u903b\u8f91\u4fee\u6539\u5b8c\u6574\u7684 Resource \u5b9e\u4f8b\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5c06\u91d1\u5e01 gold \u548c\u6728\u6750 wood \u5c5e\u6027\u4f5c\u4e3a\u53ea\u8bfb\u5c5e\u6027\u5f00\u653e\u7ed9\u5916\u90e8\u5176\u4ed6\u7c7b\uff1a<\/p>\n
\r\nstruct Resources { \r\n private(set) var gold: Int \r\n private(set) var wood: Int \r\n \r\n init(gold: Int, wood: Int) { \r\n self.gold = gold \r\n self.wood = wood \r\n } \r\n}\r\n<\/pre>\n\u53e6\u4e00\u79cd\u5b9e\u73b0\u65b9\u6cd5 \u2014 \u53ef\u53d8\u51fd\u6570<\/strong><\/div>\n\u53e6\u4e00\u79cd\u6211\u4eec\u53ef\u4ee5\u89e3\u51b3\u4e0a\u9762\u7684 Resources \u95ee\u9898\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u53ef\u53d8\u51fd\u6570\u800c\u4e0d\u662f\u64cd\u4f5c\u7b26\u91cd\u8f7d\u3002\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e2a\u51fd\u6570\uff0c\u901a\u8fc7\u53e6\u4e00\u4e2a\u5b9e\u4f8b\u51cf\u5c11 Resources \u503c\u7684\u5c5e\u6027\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\nextension Resources { \r\n mutating func reduce(by resources: Resources) { \r\n gold -= resources.gold \r\n wood -= resources.wood \r\n } \r\n}\r\n<\/pre>\n\u8fd9\u4e24\u4e2a\u89e3\u51b3\u65b9\u6848\u90fd\u6709\u5b83\u4eec\u7684\u4f18\u70b9\uff0c\u60a8\u53ef\u4ee5\u4e89\u8fa9\u8bf4\u53ef\u53d8\u51fd\u6570\u65b9\u6cd5\u66f4\u660e\u786e\u3002\u4f46\u662f\uff0c\u60a8\u4e5f\u4e0d\u5e0c\u671b\u6570\u5b66\u7684\u6807\u51c6\u51cf\u6cd5API\u53d8\u6210\uff1a5.reduce(by: 3)\uff0c\u6240\u4ee5\u4e5f\u8bb8\u8fd9\u662f\u4e00\u4e2a\u8fd0\u7b97\u7b26\u91cd\u8f7d\u8868\u73b0\u5b8c\u7f8e\u7684\u5730\u65b9\u3002<\/p>\n
\u5e03\u5c40\u8ba1\u7b97<\/strong><\/div>\n\u8ba9\u6211\u4eec\u6765\u770b\u770b\u53e6\u4e00\u79cd\u65b9\u6848\uff0c\u5176\u4e2d\u4f7f\u7528\u64cd\u4f5c\u7b26\u91cd\u8f7d\u53ef\u80fd\u975e\u5e38\u597d\u3002\u5c3d\u7ba1\u6211\u4eec\u62e5\u6709\u81ea\u52a8\u5e03\u5c40\u548c\u5f3a\u5927\u7684\u5e03\u5c40API\uff0c\u4f46\u6709\u65f6\u6211\u4eec\u53d1\u73b0\u81ea\u5df1\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u9700\u8981\u8fdb\u884c\u624b\u52a8\u5e03\u5c40\u8ba1\u7b97\u3002<\/p>\n
\u5728\u8fd9\u6837\u7684\u60c5\u51b5\u4e0b\uff0c\u5b83\u975e\u5e38\u5e38\u89c1\uff0c\u5fc5\u987b\u5728\u4e8c\u7ef4\u503c\u4e0a\u8fdb\u884c\u6570\u5b66\u64cd\u4f5c \u2014\u2014 \u5982 CGPoint\uff0cCGSize \u548c CGVector\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u4f7f\u7528\u56fe\u50cf\u89c6\u56fe\u7684\u5927\u5c0f\u548c\u4e00\u4e9b\u989d\u5916\u7684\u8fb9\u8ddd\u6765\u8ba1\u7b97\u6807\u7b7e\u7684\u539f\u70b9\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\nlabel.frame.origin = CGPoint( \r\n x: imageView.bounds.width + 10, \r\n y: imageView.bounds.height + 20 \r\n)\r\n<\/pre>\n\u5982\u679c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u6dfb\u52a0\u5b83\u4eec\uff0c\u800c\u4e0d\u662f\u5fc5\u987b\u59cb\u7ec8\u5c55\u5f00 point \u548c size \u6765\u4f7f\u7528\u4ed6\u4eec\u7684\u5e95\u5c42\u7ec4\u4ef6\uff0c\u8fd9\u4f1a\u4e0d\u4f1a\u5f88\u597d(\u5c31\u50cf\u4e0a\u9762\u5bf9 Resources \u7684\u64cd\u4f5c\u4e00\u6837)?<\/p>\n
\u4e3a\u4e86\u80fd\u591f\u8fd9\u6837\u505a\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u91cd\u8f7d+\u8fd0\u7b97\u7b26\u6765\u63a5\u53d7\u4e24\u4e2a CGSize \u5b9e\u4f8b\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u8f93\u51fa CGPoint \u503c\uff1a<\/p>\n
\r\nextension CGSize { \r\n static func +(lhs: CGSize, rhs: CGSize) -> CGPoint { \r\n return CGPoint( \r\n x: lhs.width + rhs.width, \r\n y: lhs.height + rhs.height \r\n ) \r\n } \r\n}\r\n<\/pre>\n\u901a\u8fc7\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u73b0\u5728\u53ef\u4ee5\u5199\u4e0b\u6211\u4eec\u7684\u5e03\u5c40\u8ba1\u7b97\uff1a<\/p>\n
label.frame.origin = imageView.bounds.size + CGSize(width: 10, height: 20) <\/pre>\n\u8fd9\u5f88\u9177\uff0c\u4f46\u5fc5\u987b\u4e3a\u6211\u4eec\u7684\u4f4d\u7f6e\u521b\u9020 CGSize \u4f1a\u611f\u5230\u6709\u70b9\u5947\u602a\u3002\u4f7f\u8fd9\u4e2a\u6709\u70b9\u66f4\u597d\u7684\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u662f\u5b9a\u4e49\u53e6\u4e00\u4e2a + \u91cd\u8f7d\uff0c\u8be5 + \u91cd\u8f7d\u63a5\u53d7\u5305\u542b\u4e24\u4e2a CGFloat \u503c\u7684\u5143\u7ec4\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\nextension CGSize { \r\n static func +(lhs: CGSize, rhs: (x: CGFloat, y: CGFloat)) -> CGPoint { \r\n return CGPoint( \r\n x: lhs.width + rhs.x, \r\n y: lhs.height + rhs.y \r\n ) \r\n } \r\n}\r\n<\/pre>\n\u8fd9\u8ba9\u6211\u4eec\u5728\u8fd9\u4e24\u79cd\u65b9\u5f0f\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u5199\u4e0b\u6211\u4eec\u7684\u5e03\u5c40\u8ba1\u7b97\uff1a<\/p>\n
\r\n\/\/ \u4f7f\u7528\u5143\u7ec4\u6807\u7b7e: \r\nlabel.frame.origin = imageView.bounds.size + (x: 10, y: 20) \r\n \r\n\/\/ \u6216\u8005\u4e0d\u5199: \r\nlabel.frame.origin = imageView.bounds.size + (10, 20) \r\n<\/pre>\n\u90a3\u975e\u5e38\u7d27\u51d1\uff0c\u5f88\u597d!\u4f46\u73b0\u5728\u6211\u4eec\u6b63\u5728\u63a5\u8fd1\u5bfc\u81f4\u64cd\u4f5c\u7b26\u7684\u4e89\u8bba\u51fa\u73b0\u7684\u6838\u5fc3\u95ee\u9898 \u2014\u2014 \u5e73\u8861\u5197\u4f59\u7a0b\u5ea6\u548c\u53ef\u8bfb\u6027\u3002\u7531\u4e8e\u6211\u4eec\u4ecd\u7136\u5904\u7406\u6570\u5b57\uff0c\u6211\u8ba4\u4e3a\u5927\u591a\u6570\u4eba\u4f1a\u53d1\u73b0\u4e0a\u9762\u7684\u6613\u4e8e\u9605\u8bfb\u548c\u7406\u89e3\uff0c\u4f46\u968f\u7740\u6211\u4eec\u7ee7\u7eed\u81ea\u5b9a\u4e49\u64cd\u4f5c\u7b26\u7684\u7528\u9014\uff0c\u5b83\u53d8\u5f97\u66f4\u52a0\u590d\u6742\uff0c\u7279\u522b\u662f\u5f53\u6211\u4eec\u5f00\u59cb\u5f15\u5165\u5168\u65b0\u7684\u64cd\u4f5c\u7b26\u65f6\u3002<\/p>\n
\u5904\u7406\u9519\u8bef\u7684\u81ea\u5b9a\u4e49\u8fd0\u7b97\u7b26<\/strong><\/div>\n\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u8fd8\u53ea\u662f\u7b80\u5355\u7684\u91cd\u8f7d\u4e86\u7cfb\u7edf\u5df2\u7ecf\u5b58\u5728\u7684\u64cd\u4f5c\u7b26\u3002\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u60f3\u5f00\u59cb\u4f7f\u7528\u65e0\u6cd5\u771f\u6b63\u6620\u5c04\u5230\u73b0\u6709\u7684\u529f\u80fd\u7684\u64cd\u4f5c\u7b26\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u81ea\u5df1\u7684\u3002<\/p>\n
\u8ba9\u6211\u4eec\u6765\u770b\u770b\u53e6\u4e00\u4e2a\u4f8b\u5b50\u3002Swift \u7684 do\uff0ctry\uff0ccatch \u9519\u8bef\u5904\u7406\u673a\u5236\u5728\u5904\u7406\u65e0\u6cd5\u4f7f\u7528\u7684\u540c\u6b65\u64cd\u4f5c\u65f6\u8d85\u7ea7\u6f02\u4eae\u3002\u5b83\u53ef\u4ee5\u8ba9\u6211\u4eec\u5728\u51fa\u73b0\u9519\u8bef\u540e\uff0c\u8f7b\u677e\u5b89\u5168\u5730\u9000\u51fa\u51fd\u6570\u3002\u4f8b\u5982\u5728\u52a0\u8f7d\u78c1\u76d8\u4e0a\u4fdd\u5b58\u7684\u6570\u636e\u6a21\u578b\u65f6\uff1a<\/p>\n
\r\nclass NoteManager { \r\n func loadNote(fromFileNamed fileName: String) throws -> Note { \r\n let file = try fileLoader.loadFile(named: fileName) \r\n let data = try file.read() \r\n let note = try Note(data: data) \r\n return note \r\n } \r\n}\r\n<\/pre>\n\u505a\u51fa\u50cf\u4e0a\u9762\u7684\u552f\u4e00\u4e3b\u8981\u7684\u7f3a\u70b9\u662f\u6211\u4eec\u76f4\u63a5\u5411\u6211\u4eec\u529f\u80fd\u7684\u8c03\u7528\u8005\u629b\u51fa\u51fa\u4efb\u4f55\u6f5c\u5728\u7684\u9519\u8bef\uff0c\u9700\u8981\u51cf\u5c11 API \u53ef\u4ee5\u629b\u51fa\u7684\u9519\u8bef\u91cf\uff0c\u5426\u5219\u505a\u6709\u610f\u4e49\u7684\u9519\u8bef\u5904\u7406\u548c\u6d4b\u8bd5\u53d8\u5f97\u975e\u5e38\u56f0\u96be\u3002<\/p>\n
\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u60f3\u8981\u7684\u662f\u7ed9\u5b9a API \u53ef\u4ee5\u629b\u51fa\u7684\u6709\u9650\u9519\u8bef\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u8f7b\u677e\u5730\u5355\u72ec\u5904\u7406\u6bcf\u79cd\u60c5\u51b5\u3002\u8ba9\u6211\u4eec\u8bf4\u6211\u4eec\u4e5f\u60f3\u6355\u6349\u6240\u6709\u6f5c\u5728\u7684\u9519\u8bef\uff0c\u8ba9\u6211\u4eec\u540c\u65f6\u62e5\u6709\u6240\u6709\u597d\u7684\u4e8b\u60c5\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u4f7f\u7528\u663e\u5f0f cases \u5b9a\u4e49\u4e00\u4e2a\u9519\u8bef\u679a\u4e3e\uff0c\u6bcf\u4e2a\u9519\u8bef\u7684\u679a\u4e3e\u90fd\u4f7f\u7528\u5e95\u5c42\u9519\u8bef\u7684\u5173\u8054\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\nextension NoteManager { \r\n enum LoadingError: Error { \r\n case invalidFile(Error) \r\n case invalidData(Error) \r\n case decodingFailed(Error) \r\n } \r\n} \r\n<\/pre>\n\u4f46\u662f\uff0c\u6355\u83b7\u6f5c\u5728\u7684\u9519\u8bef\u5e76\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u81ea\u5df1\u7c7b\u578b\u662f\u68d8\u624b\u7684\u3002\u6211\u4eec\u5fc5\u987b\u5199\u4e0b\u7c7b\u4f3c\u7684\u6807\u51c6\u9519\u8bef\u5904\u7406\u673a\u5236\uff1a<\/p>\n
\r\nclass NoteManager { \r\n func loadNote(fromFileNamed fileName: String) throws -> Note { \r\n do { \r\n let file = try fileLoader.loadFile(named: fileName) \r\n \r\n do { \r\n let data = try file.read() \r\n \r\n do { \r\n return try Note(data: data) \r\n } catch { \r\n throw LoadingError.decodingFailed(error) \r\n } \r\n } catch { \r\n throw LoadingError.invalidData(error) \r\n } \r\n } catch { \r\n throw LoadingError.invalidFile(error) \r\n } \r\n } \r\n}\r\n<\/pre>\n\u6211\u4e0d\u8ba4\u4e3a\u6709\u4eba\u60f3\u8981\u9605\u8bfb\u50cf\u4e0a\u9762\u7684\u4ee3\u7801\u3002\u4e00\u4e2a\u9009\u9879\u662f\u4ecb\u7ecd\u4e00\u4e2a perform \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7528\u6765\u628a\u4e00\u4e2a\u9519\u8bef\u8f6c\u6362\u4e3a\u53e6\u4e00\u4e2a\u9519\u8bef\uff1a<\/p>\n
\r\nclass NoteManager { \r\n func loadNote(fromFileNamed fileName: String) throws -> Note { \r\n let file = try perform(fileLoader.loadFile(named: fileName), \r\n orThrow: LoadingError.invalidFile) \r\n \r\n let data = try perform(file.read(), \r\n orThrow: LoadingError.invalidData) \r\n \r\n let note = try perform(Note(data: data), \r\n orThrow: LoadingError.decodingFailed) \r\n \r\n return note \r\n } \r\n} \r\n \r\nfunc perform(_ expression: @autoclosure () throws -> T, \r\n errorTransform: (Error) -> Error) throws -> T { \r\n do { \r\n return try expression() \r\n } catch { \r\n throw errorTransform(error) \r\n } \r\n} \r\n<\/t><\/pre>\n\u66f4\u597d\u4e00\u70b9\u4e86\uff0c\u4f46\u6211\u4eec\u4ecd\u7136\u6709\u5f88\u591a\u9519\u8bef\u8f6c\u6362\u4ee3\u7801\u4f1a\u5bf9\u6211\u4eec\u7684\u5b9e\u9645\u903b\u8f91\u9020\u6210\u6df7\u4e71\u3002\u8ba9\u6211\u4eec\u770b\u770b\u5f15\u5165\u65b0\u7684\u64cd\u4f5c\u7b26\u662f\u5426\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u6e05\u7406\u6b64\u4ee3\u7801\u3002<\/p>\n
\u6dfb\u52a0\u65b0\u7684\u64cd\u4f5c\u7b26<\/strong><\/div>\n\u6211\u4eec\u9996\u5148\u5b9a\u4e49\u6211\u4eec\u7684\u65b0\u8fd0\u8425\u5546\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u5c06\u9009\u62e9 \u301c> \u4f5c\u4e3a\u7b26\u53f7(\u5177\u6709\u66ff\u4ee3\u8fd4\u56de\u7c7b\u578b\u7684\u52a8\u673a\uff0c\u6240\u4ee5\u6211\u4eec\u6b63\u5728\u5bfb\u627e\u7c7b\u4f3c\u4e8e ->)\u7684\u4e1c\u897f\u3002\u7531\u4e8e\u8fd9\u662f\u4e00\u4e2a\u5c06\u5728\u4e24\u4fa7\u5de5\u4f5c\u64cd\u4f5c\u7b26\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u5176\u5b9a\u4e49\u4e3a infix\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n
\r\ninfix operator ~> \r\n<\/pre>\n\u4f7f\u64cd\u4f5c\u7b26\u5982\u6b64\u5f3a\u5927\u7684\u662f\u5b83\u4eec\u53ef\u4ee5\u81ea\u52a8\u6355\u6349\u5b83\u4eec\u4e24\u4fa7\u7684\u4e0a\u4e0b\u6587\u3002\u5c06\u5176\u4e0eSwift \u7684 @autoclosure \u529f\u80fd\u76f8\u7ed3\u5408\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e9b\u975e\u5e38\u9177\u7684\u4e1c\u897f\u3002<\/p>\n
\u8ba9\u6211\u4eec\u5b9e\u73b0 \u301c> \u4f5c\u4e3a\u4f20\u9012\u8868\u8fbe\u5f0f\u548c\u8f6c\u6362\u9519\u8bef\u7684\u64cd\u4f5c\u7b26\uff0c\u629b\u51fa\u6216\u8fd4\u56de\u4e0e\u539f\u59cb\u8868\u8fbe\u5f0f\u76f8\u540c\u7684\u7c7b\u578b\uff1a<\/p>\n
\r\nfunc ~>(expression: @autoclosure () throws -> T, \r\n errorTransform: (Error) -> Error) throws -> T { \r\n do { \r\n return try expression() \r\n } catch { \r\n throw errorTransform(error) \r\n } \r\n} \r\n<\/t><\/pre>\n\u90a3\u4e48\u4e0a\u8ff0\u8fd9\u4e2a\u64cd\u4f5c\u7b26\u80fd\u591f\u8ba9\u6211\u4eec\u505a\u4ec0\u4e48\u5462?\u7531\u4e8e\u679a\u4e3e\u5177\u6709\u5173\u8054\u503c\u7684\u9759\u6001\u51fd\u6570\u5728Swift\u4e2d\u4e5f\u662f\u9759\u6001\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u7b80\u5355\u5730\u5728\u6211\u4eec\u7684\u629b\u51fa\u8868\u8fbe\u5f0f\u548c\u9519\u8bef\u60c5\u51b5\u4e4b\u95f4\u6dfb\u52a0\u301c>\u64cd\u4f5c\u7b26\uff0c\u6211\u4eec\u5e0c\u671b\u5c06\u4efb\u4f55\u5e95\u5c42\u9519\u8bef\u8f6c\u6362\u4e3a\u5982\u4e0b\u5f62\u5f0f\uff1a<\/p>\n
\r\nclass NoteManager { \r\n func loadNote(fromFileNamed fileName: String) throws -> Note { \r\n let file = try fileLoader.loadFile(named: fileName) ~> LoadingError.invalidFile \r\n let data = try file.read() ~> LoadingError.invalidData \r\n let note = try Note(data: data) ~> LoadingError.decodingFailed \r\n return note \r\n } \r\n} \r\n<\/pre>\n\u8fd9\u5f88\u9177!\u901a\u8fc7\u4f7f\u7528\u64cd\u4f5c\u7b26\uff0c\u6211\u4eec\u5df2\u4ece\u6211\u4eec\u7684\u903b\u8f91\u4e2d\u5220\u9664\u4e86\u5927\u91cf\u7684\u7e41\u7410\u4ee3\u7801\u548c\u8bed\u6cd5\uff0c\u4f7f\u6211\u4eec\u7684\u4ee3\u7801\u66f4\u4e3a\u805a\u7126\u3002\u7136\u800c\uff0c\u7f3a\u70b9\u662f\u6211\u4eec\u5f15\u5165\u4e86\u4e00\u4e2a\u65b0\u7684\u9519\u8bef\u5904\u7406\u8bed\u6cd5\uff0c\u8fd9\u53ef\u80fd\u662f\u4efb\u4f55\u53ef\u80fd\u5728\u672a\u6765\u52a0\u5165\u6211\u4eec\u9879\u76ee\u7684\u65b0\u5f00\u53d1\u4eba\u5458\u5b8c\u5168\u4e0d\u719f\u6089\u7684\u3002<\/p>\n
\u7ed3\u8bba<\/strong><\/div>\n\u81ea\u5b9a\u4e49\u64cd\u4f5c\u7b26\u548c\u64cd\u4f5c\u7b26\u91cd\u8f7d\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u8ba9\u6211\u4eec\u6784\u5efa\u975e\u5e38\u6709\u8da3\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5b83\u53ef\u4ee5\u8ba9\u6211\u4eec\u964d\u4f4e\u5448\u73b0\u578b\u51fd\u6570\u8c03\u7528\u7684\u5197\u957f\uff0c\u8fd9\u53ef\u80fd\u4f1a\u7ed9\u6211\u4eec\u6e05\u6d01\u4ee3\u7801\u3002\u7136\u800c\uff0c\u5b83\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u6ed1\u5761\uff0c\u53ef\u4ee5\u5f15\u5bfc\u6211\u4eec\u7f16\u5199\u9690\u79d8\u7684\u548c\u96be\u4ee5\u9605\u8bfb\u7684\u4ee3\u7801\uff0c\u8fd9\u5bf9\u5176\u4ed6\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u53d8\u5f97\u975e\u5e38\u4ee4\u4eba\u6050\u60e7\u548c\u6df7\u6dc6\u3002<\/p>\n
\u5c31\u50cf\u4ee5\u66f4\u9ad8\u7ea7\u7684\u65b9\u5f0f\u4f7f\u7528\u7b2c\u4e00\u7c7b\u51fd\u6570\u65f6\uff0c\u6211\u8ba4\u4e3a\u5728\u5f15\u5165\u65b0\u7684\u8fd0\u7b97\u7b26\u6216\u521b\u5efa\u989d\u5916\u7684\u91cd\u8f7d\u524d\uff0c\u9700\u8981\u4e09\u601d\u800c\u540e\u884c\u3002\u4ece\u5176\u4ed6\u5f00\u53d1\u4eba\u5458\u83b7\u5f97\u53cd\u9988\u4e5f\u53ef\u4ee5\u8d85\u7ea7\u6709\u4ef7\u503c\uff0c\u4f5c\u4e3a\u4e00\u79cd\u65b0\u7684\u64cd\u4f5c\u7b26\uff0c\u5bf9\u60a8\u7684\u611f\u89c9\u548c\u5bf9\u522b\u4eba\u7684\u611f\u89c9\u5b8c\u5168\u4e0d\u4e00\u6837\u3002\u4e0e\u5982\u6b64\u591a\u7684\u4e8b\u60c5\u4e00\u6837\uff0c\u7406\u89e3\u6743\u8861\u5e76\u8bd5\u56fe\u4e3a\u6bcf\u79cd\u60c5\u51b5\u6311\u9009\u6700\u5408\u9002\u7684\u5de5\u5177\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5f88\u5c11\u6709Swift\u529f\u80fd\u80fd\u548c\u4f7f\u7528\u81ea\u5b9a\u4e49\u64cd\u4f5c\u7b26\u7684\u4e00\u6837\u4ea7\u751f\u5982\u6b64\u591a\u7684\u6fc0\u70c8\u8fa9\u8bba\u3002\u867d\u7136\u6709\u4e9b\u4eba\u53d1\u73b0\u5b83\u4eec\u771f\u7684\u6709\u7528\uff0c\u53ef\u4ee5\u964d\u4f4e\u4ee3\u7801\u5197 […]<\/p>\n","protected":false},"author":1329,"featured_media":221990,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-221988","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=221988"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221988\/revisions"}],"predecessor-version":[{"id":221991,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221988\/revisions\/221991"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/221990"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=221988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=221988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=221988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}