{"id":6266,"date":"2024-07-10T13:43:22","date_gmt":"2024-07-10T05:43:22","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6266"},"modified":"2024-07-10T13:43:22","modified_gmt":"2024-07-10T05:43:22","slug":"swift-%e5%b8%b8%e8%a7%81%e9%9d%a2%e8%af%95%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6266","title":{"rendered":"Swift \u5e38\u89c1\u9762\u8bd5\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u975e\u539f\u521b\uff0cGemini \u95ee\u7b54\u751f\u6210<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swift \u5e38\u89c1\u9762\u8bd5\u95ee\u9898<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Swift \u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684\u73b0\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c\u7528\u4e8e\u6784\u5efa iOS\u3001macOS\u3001watchOS\u3001tvOS \u548c Linux \u5e94\u7528\u7a0b\u5e8f\u3002\u8fd1\u5e74\u6765\uff0cSwift \u5df2\u6210\u4e3a\u5f00\u53d1\u4eba\u5458\u7684\u9996\u9009\u8bed\u8a00\u4e4b\u4e00\uff0c\u56e0\u6b64\u5728\u9762\u8bd5\u4e2d\u4e86\u89e3\u4e00\u4e9b\u5e38\u89c1\u7684 Swift \u9762\u8bd5\u95ee\u9898\u975e\u5e38\u91cd\u8981\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u9762\u8bd5\u95ee\u9898\uff0c\u6db5\u76d6\u4e86 Swift \u7684\u5404\u4e2a\u65b9\u9762\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u57fa\u7840\u77e5\u8bc6<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u89e3\u91ca Swift \u548c Objective-C \u4e4b\u95f4\u7684\u533a\u522b\u3002<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u53ef\u9009\u7c7b\u578b\uff1f\u5982\u4f55\u5904\u7406\u53ef\u9009\u7c7b\u578b\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u9519\u8bef\u5904\u7406\uff1f\u5982\u4f55\u5728 Swift \u4e2d\u5904\u7406\u9519\u8bef\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u95ed\u5305\uff1f\u95ed\u5305\u7684\u7528\u9014\u662f\u4ec0\u4e48\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u534f\u8bae\uff1f\u5982\u4f55\u4f7f\u7528\u534f\u8bae\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u6cdb\u578b\uff1f\u6cdb\u578b\u7684\u7528\u9014\u662f\u4ec0\u4e48\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u5185\u5b58\u7ba1\u7406\uff1f\u5982\u4f55\u5728 Swift \u4e2d\u7ba1\u7406\u5185\u5b58\uff1f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9ad8\u7ea7\u4e3b\u9898<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u89e3\u91ca\u503c\u7c7b\u578b\u548c\u5f15\u7528\u7c7b\u578b\u4e4b\u95f4\u7684\u533a\u522b\u3002<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u7ed3\u6784\u4f53\uff1f\u5982\u4f55\u4f7f\u7528\u7ed3\u6784\u4f53\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u679a\u4e3e\uff1f\u5982\u4f55\u4f7f\u7528\u679a\u4e3e\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u7c7b\uff1f\u5982\u4f55\u4f7f\u7528\u7c7b\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u7ee7\u627f\uff1f\u5982\u4f55\u4f7f\u7528\u7ee7\u627f\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u534f\u8bae\u7ee7\u627f\uff1f\u5982\u4f55\u4f7f\u7528\u534f\u8bae\u7ee7\u627f\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u5173\u8054\u7c7b\u578b\uff1f\u5982\u4f55\u4f7f\u7528\u5173\u8054\u7c7b\u578b\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u7c7b\u578b\u6269\u5c55\uff1f\u5982\u4f55\u4f7f\u7528\u7c7b\u578b\u6269\u5c55\uff1f<\/li>\n\n\n\n<li>\u4ec0\u4e48\u662f\u6cdb\u578b\u7c7b\u578b\u6269\u5c55\uff1f\u5982\u4f55\u4f7f\u7528\u6cdb\u578b\u7c7b\u578b\u6269\u5c55\uff1f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7f16\u7801\u95ee\u9898<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\u7684\u4e58\u79ef\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u56de\u6587\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u67e5\u627e\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u5143\u7d20\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u521b\u5efa\u4e24\u4e2a\u7c7b\u4e4b\u95f4\u5b9e\u4f8b\u7684\u6620\u5c04\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u5bf9\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u3002<\/li>\n\n\n\n<li>\u7f16\u5199\u4e00\u4e2a\u51fd\u6570\u6765\u4f7f\u7528\u5f02\u6b65\u64cd\u4f5c\u4ece\u7f51\u7edc\u83b7\u53d6\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5176\u4ed6\u95ee\u9898<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u60a8\u6700\u559c\u6b22\u7684 Swift \u7279\u6027\u662f\u4ec0\u4e48\uff1f<\/li>\n\n\n\n<li>\u60a8\u5982\u4f55\u8ddf\u4e0a Swift \u7684\u6700\u65b0\u53d1\u5c55\uff1f<\/li>\n\n\n\n<li>\u60a8\u5728\u4f7f\u7528 Swift \u65f6\u9047\u5230\u8fc7\u54ea\u4e9b\u6311\u6218\uff1f\u60a8\u5982\u4f55\u514b\u670d\u8fd9\u4e9b\u6311\u6218\uff1f<\/li>\n\n\n\n<li>\u60a8\u5bf9 Swift \u7684\u672a\u6765\u6709\u4f55\u770b\u6cd5\uff1f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u51c6\u5907\u8fd9\u4e9b\u5e38\u89c1\u95ee\u9898\u4e4b\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u63aa\u65bd\u6765\u51c6\u5907 Swift \u9762\u8bd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7ec3\u4e60\u7f16\u7801\uff1a\u82b1\u65f6\u95f4\u7ec3\u4e60\u7f16\u7801 Swift\uff0c\u4ee5\u63d0\u9ad8\u60a8\u7684\u6280\u80fd\u5e76\u5efa\u7acb\u4fe1\u5fc3\u3002<\/li>\n\n\n\n<li>\u719f\u6089 Swift \u6807\u51c6\u5e93\uff1a\u4e86\u89e3 Swift \u6807\u51c6\u5e93\u4e2d\u53ef\u7528\u7684\u5404\u79cd\u7c7b\u3001\u7ed3\u6784\u4f53\u548c\u51fd\u6570\u3002<\/li>\n\n\n\n<li>\u4e86\u89e3\u6d41\u884c\u7684 Swift \u6846\u67b6\uff1a\u4e86\u89e3\u4e00\u4e9b\u6d41\u884c\u7684 Swift \u6846\u67b6\uff0c\u4f8b\u5982 Combine \u548c Vapor\u3002<\/li>\n\n\n\n<li>\u51c6\u5907\u56de\u7b54\u6709\u5173\u60a8\u8fc7\u53bb\u7ecf\u9a8c\u7684\u95ee\u9898\uff1a\u51c6\u5907\u597d\u8ba8\u8bba\u60a8\u4f7f\u7528 Swift \u7684\u8fc7\u53bb\u7ecf\u9a8c\uff0c\u5305\u62ec\u60a8\u6240\u4ece\u4e8b\u8fc7\u7684\u9879\u76ee\u548c\u60a8\u514b\u670d\u7684\u6311\u6218\u3002<\/li>\n\n\n\n<li>\u4fdd\u6301\u79ef\u6781\u7684\u6001\u5ea6\uff1a\u5bf9\u9762\u8bd5\u5145\u6ee1\u4fe1\u5fc3\u548c\u79ef\u6781\u7684\u6001\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u5145\u5206\u51c6\u5907\uff0c\u60a8\u53ef\u4ee5\u589e\u52a0\u5728 Swift \u9762\u8bd5\u4e2d\u53d6\u5f97\u6210\u529f\u7684\u673a\u4f1a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e00\u4e9b\u989d\u5916\u7684\u8d44\u6e90\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u51c6\u5907 Swift \u9762\u8bd5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/juejin.cn\/post\/7229877486171930684\" target=\"_blank\" rel=\"noreferrer noopener\">Swift \u9762\u8bd5\u9898\u6c47\u603b<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/blog.csdn.net\/zhishijike\/article\/details\/136766746\" target=\"_blank\" rel=\"noreferrer noopener\">iOS Swift\u5f00\u53d1\u9762\u8bd5\u9898\u603b\u7ed3<\/a><\/li>\n\n\n\n<li>Swift \u9762\u8bd5\u9898\u53ca\u7b54\u6848\u6574\u7406 [\u79fb\u9664\u4e86\u65e0\u6548\u7f51\u5740]<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ee\uff1a\u8be6\u7ec6\u89e3\u91ca<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Swift \u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u89e3\u7b54\uff08\u7b80\u4f53\u4e2d\u6587\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u57fa\u7840\u77e5\u8bc6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. \u89e3\u91ca Swift \u548c Objective-C \u4e4b\u95f4\u7684\u533a\u522b\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift \u548c Objective-C \u90fd\u662f\u7528\u4e8e\u5f00\u53d1 iOS\u3001macOS\u3001watchOS\u3001tvOS \u548c Linux \u5e94\u7528\u7a0b\u5e8f\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u4f46\u662f\uff0c\u5b83\u4eec\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8bed\u6cd5:<\/strong> Swift \u5177\u6709\u66f4\u7b80\u6d01\u3001\u66f4\u73b0\u4ee3\u7684\u8bed\u6cd5\uff0c\u800c Objective-C \u5219\u66f4\u52a0\u5197\u957f\u4e14\u7c7b\u4f3c C \u8bed\u8a00\u3002<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u6027:<\/strong> Swift \u662f\u4e00\u79cd\u7c7b\u578b\u5b89\u5168\u8bed\u8a00\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u5e2e\u52a9\u9632\u6b62\u56e0\u4f7f\u7528\u4e0d\u517c\u5bb9\u7684\u6570\u636e\u7c7b\u578b\u800c\u5bfc\u81f4\u7684\u9519\u8bef\u3002Objective-C \u4e0d\u662f\u7c7b\u578b\u5b89\u5168\u7684\uff0c\u56e0\u6b64\u66f4\u5bb9\u6613\u53d1\u751f\u8fd0\u884c\u65f6\u9519\u8bef\u3002<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u7ba1\u7406:<\/strong> Swift \u4f7f\u7528\u81ea\u52a8\u5f15\u7528\u8ba1\u6570 (ARC) \u8fdb\u884c\u5185\u5b58\u7ba1\u7406\uff0c\u5b83\u4f1a\u81ea\u52a8\u7ba1\u7406\u5185\u5b58\u7684\u5206\u914d\u548c\u91ca\u653e\u3002Objective-C \u9700\u8981\u4f7f\u7528 retain \u548c release \u7b49\u6280\u672f\u8fdb\u884c\u624b\u52a8\u5185\u5b58\u7ba1\u7406\u3002<\/li>\n\n\n\n<li><strong>\u95ed\u5305:<\/strong> Swift \u5177\u6709\u5185\u7f6e\u7684\u95ed\u5305\u652f\u6301\uff0c\u95ed\u5305\u662f\u53ef\u4ee5\u5728\u5176\u5c01\u95ed\u4f5c\u7528\u57df\u4e2d\u6355\u83b7\u53d8\u91cf\u7684\u4ee3\u7801\u5757\u3002Objective-C \u6ca1\u6709\u539f\u751f\u95ed\u5305\u652f\u6301\u3002<\/li>\n\n\n\n<li><strong>\u534f\u8bae:<\/strong> Swift \u4f7f\u7528\u534f\u8bae\u6765\u5b9a\u4e49\u4e0d\u540c\u7c7b\u578b\u4e4b\u95f4\u7684\u5171\u540c\u884c\u4e3a\u3002Objective-C \u4e5f\u4f7f\u7528\u534f\u8bae\uff0c\u4f46\u5176\u534f\u8bae\u7cfb\u7edf\u4e0d\u591f\u7075\u6d3b\u548c\u5f3a\u5927\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. \u4ec0\u4e48\u662f\u53ef\u9009\u7c7b\u578b\uff1f\u5982\u4f55\u5904\u7406\u53ef\u9009\u7c7b\u578b\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift \u4e2d\u7684\u53ef\u9009\u7c7b\u578b\u8868\u793a\u53ef\u80fd\u5b58\u5728\u6216\u4e0d\u5b58\u5728\u7684\u503c\u3002\u5b83\u4eec\u5728\u7c7b\u578b\u540d\u79f0\u540e\u7528\u95ee\u53f7 (?) \u8868\u793a\u3002\u4f8b\u5982\uff0c<code class=\"\">Int?<\/code> \u8868\u793a\u53ef\u9009\u7684\u6574\u6570\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5904\u7406\u53ef\u9009\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6280\u672f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u53ef\u9009\u7ed1\u5b9a:<\/strong> \u4f7f\u7528 <code class=\"\">if let<\/code> \u8bed\u53e5\u6765\u89e3\u5305\u53ef\u9009\u503c\uff0c\u5982\u679c\u8be5\u503c\u5b58\u5728\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let numString: String = \"123\"\n\nif let num = Int(numString) {\n    print(num) \/\/ \u8f93\u51fa: 123\n} else {\n    print(\"Failed to convert string to integer\")\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7a7a\u503c\u5408\u5e76\u8fd0\u7b97\u7b26 (??):<\/strong> \u4f7f\u7528 <code class=\"\">??<\/code> \u8fd0\u7b97\u7b26\u5728\u53ef\u9009\u503c\u4e3a nil \u65f6\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let optionalString: String? = nil\nlet defaultString = \"Hello\"\n\nlet result = optionalString ?? defaultString\nprint(result) \/\/ \u8f93\u51fa: Hello\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u53ef\u9009\u94fe\u5f0f (?.):<\/strong> \u4f7f\u7528 <code class=\"\">?.<\/code> \u8fd0\u7b97\u7b26\u5b89\u5168\u5730\u8bbf\u95ee\u53ef\u9009\u503c\u4e0a\u7684\u5c5e\u6027\u6216\u8c03\u7528\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct Person {\n    var name: String?\n    var age: Int?\n}\n\nlet person: Person? = nil\nlet name = person?.name \/\/ nil\nlet age = person?.age \/\/ nil\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. \u4ec0\u4e48\u662f\u9519\u8bef\u5904\u7406\uff1f\u5982\u4f55\u5728 Swift \u4e2d\u5904\u7406\u9519\u8bef\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9519\u8bef\u5904\u7406\u662f\u6307\u8bc6\u522b\u3001\u62a5\u544a\u548c\u4ece\u7a0b\u5e8f\u6267\u884c\u671f\u95f4\u53d1\u751f\u7684\u9519\u8bef\u4e2d\u6062\u590d\u7684\u8fc7\u7a0b\u3002Swift \u4f7f\u7528 <code class=\"\">do-catch<\/code> \u8bed\u6cd5\u63d0\u4f9b\u4e86\u7ed3\u6784\u5316\u7684\u9519\u8bef\u5904\u7406\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>do {\n    \/\/ \u53ef\u80fd\u629b\u51fa\u9519\u8bef\u7684\u4ee3\u7801\n} catch {\n    \/\/ \u5904\u7406\u9519\u8bef\n    print(error.localizedDescription)\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7279\u5b9a\u7684\u9519\u8bef\u7c7b\u578b\u6765\u6355\u83b7\u7279\u5b9a\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum MyError: Error {\n    case invalidInput\n    case networkError\n}\n\ndo {\n    \/\/ \u53ef\u80fd\u629b\u51fa MyError \u7684\u4ee3\u7801\n} catch MyError.invalidInput {\n    print(\"Invalid input\")\n} catch MyError.networkError {\n    print(\"Network error\")\n} catch {\n    print(\"Unknown error\")\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. \u4ec0\u4e48\u662f\u95ed\u5305\uff1f\u95ed\u5305\u7684\u7528\u9014\u662f\u4ec0\u4e48\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift \u4e2d\u7684\u95ed\u5305\u662f\u53ef\u4ee5\u5728\u5176\u5c01\u95ed\u4f5c\u7528\u57df\u4e2d\u6355\u83b7\u53d8\u91cf\u5e76\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u51fd\u6570\u6216\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\u7684\u4ee3\u7801\u5757\u3002\u5b83\u4eec\u901a\u5e38\u7528\u4e8e\u7f16\u5199\u7b80\u6d01\u4e14\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ed\u5305\u7684\u5e38\u89c1\u7528\u9014\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u56de\u8c03:<\/strong> \u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\u4ee5\u4f9b\u7a0d\u540e\u8c03\u7528\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u5904\u7406:<\/strong> \u8fc7\u6ee4\u3001\u6392\u5e8f\u6216\u8f6c\u6362\u6570\u636e\u96c6\u5408\u3002<\/li>\n\n\n\n<li><strong>UI \u4e8b\u4ef6\u5904\u7406:<\/strong> \u54cd\u5e94\u7528\u6237\u4e0e UI \u5143\u7d20\u7684\u4ea4\u4e92\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. \u4ec0\u4e48\u662f\u534f\u8bae\uff1f\u5982\u4f55\u4f7f\u7528\u534f\u8bae\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift \u4e2d\u7684\u534f\u8bae\u5b9a\u4e49\u4e86\u4e00\u7ec4\u7c7b\u578b\u53ef\u4ee5\u9075\u5faa\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u4e00\u79cd\u5728\u4e0d\u8fdb\u884c\u5b50\u7c7b\u5316\u7684\u60c5\u51b5\u4e0b\u5b9a\u4e49\u4e0d\u540c\u7c7b\u578b\u4e4b\u95f4\u5171\u540c\u884c\u4e3a\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4f7f\u7528\u534f\u8bae\uff0c\u60a8\u9996\u5148\u9700\u8981\u4f7f\u7528 <code class=\"\">protocol<\/code> \u5173\u952e\u5b57\u5b9a\u4e49\u5b83\u3002\u7136\u540e\uff0c\u7c7b\u578b\u53ef\u4ee5\u901a\u8fc7\u5b9e\u73b0\u5176\u6240\u9700\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u6765\u9075\u5faa\u534f\u8bae\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Swift<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protocol Shape {\n    func area() -&gt; Double\n    func perimeter() -&gt; Double\n}\n\nstruct Circle: Shape {\n    let radius: Double\n\n    func area() -&gt; Double {\n        .pi * radius * radius\n    }\n\n    func perimeter() -&gt; Double {\n        2 * .pi * radius\n    }\n}\n\nstruct Square: Shape {\n    let sideLength: Double\n\n    func area() -&gt; Double {\n        sideLength * sideLength\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u975e\u539f\u521b\uff0cGemini \u95ee\u7b54\u751f\u6210 Swift \u5e38\u89c1\u9762\u8bd5\u95ee\u9898 Swift \u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684\u73b0\u4ee3\u7f16\u7a0b\u8bed\u8a00\uff0c&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6266\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[66,67,112],"class_list":["post-6266","post","type-post","status-publish","format-standard","hentry","category-5","tag-ios","tag-swift","tag-112"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6266"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6266\/revisions"}],"predecessor-version":[{"id":6267,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6266\/revisions\/6267"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}