{"id":542,"date":"2018-02-23T23:39:07","date_gmt":"2018-02-23T15:39:07","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-%e6%9e%84%e9%80%a0%e8%bf%87%e7%a8%8b\/"},"modified":"2018-02-23T23:39:07","modified_gmt":"2018-02-23T15:39:07","slug":"swift-%e6%9e%84%e9%80%a0%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=542","title":{"rendered":"Swift \u6784\u9020\u8fc7\u7a0b"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift \u6784\u9020\u8fc7\u7a0b<\/h1>\n<p>\u6784\u9020\u8fc7\u7a0b\u662f\u4e3a\u4e86\u4f7f\u7528\u67d0\u4e2a\u7c7b\u3001\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\u7684\u5b9e\u4f8b\u800c\u8fdb\u884c\u7684\u51c6\u5907\u8fc7\u7a0b\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5305\u542b\u4e86\u4e3a\u5b9e\u4f8b\u4e2d\u7684\u6bcf\u4e2a\u5c5e\u6027\u8bbe\u7f6e\u521d\u59cb\u503c\u548c\u4e3a\u5176\u6267\u884c\u5fc5\u8981\u7684\u51c6\u5907\u548c\u521d\u59cb\u5316\u4efb\u52a1\u3002\n<\/p>\n<p>Swift \u6784\u9020\u51fd\u6570\u4f7f\u7528 init() \u65b9\u6cd5\u3002<\/p>\n<p>\u4e0e Objective-C \u4e2d\u7684\u6784\u9020\u5668\u4e0d\u540c\uff0cSwift \u7684\u6784\u9020\u5668\u65e0\u9700\u8fd4\u56de\u503c\uff0c\u5b83\u4eec\u7684\u4e3b\u8981\u4efb\u52a1\u662f\u4fdd\u8bc1\u65b0\u5b9e\u4f8b\u5728\u7b2c\u4e00\u6b21\u4f7f\u7528\u524d\u5b8c\u6210\u6b63\u786e\u7684\u521d\u59cb\u5316\u3002<\/p>\n<p>\n\u7c7b\u5b9e\u4f8b\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u6790\u6784\u5668\uff08deinitializer\uff09\u5728\u7c7b\u5b9e\u4f8b\u91ca\u653e\u4e4b\u524d\u6267\u884c\u6e05\u7406\u5185\u5b58\u7684\u5de5\u4f5c\u3002<\/p>\n<hr>\n<h2>\u5b58\u50a8\u578b\u5c5e\u6027\u7684\u521d\u59cb\u8d4b\u503c<\/h2>\n<p>\u7c7b\u548c\u7ed3\u6784\u4f53\u5728\u5b9e\u4f8b\u521b\u5efa\u65f6\uff0c\u5fc5\u987b\u4e3a\u6240\u6709\u5b58\u50a8\u578b\u5c5e\u6027\u8bbe\u7f6e\u5408\u9002\u7684\u521d\u59cb\u503c\u3002<\/p>\n<p>\n\u5b58\u50a8\u5c5e\u6027\u5728\u6784\u9020\u5668\u4e2d\u8d4b\u503c\u65f6\uff0c\u5b83\u4eec\u7684\u503c\u662f\u88ab\u76f4\u63a5\u8bbe\u7f6e\u7684\uff0c\u4e0d\u4f1a\u89e6\u53d1\u4efb\u4f55\u5c5e\u6027\u89c2\u6d4b\u5668\u3002<\/p>\n<p>\u5b58\u50a8\u5c5e\u6027\u5728\u6784\u9020\u5668\u4e2d\u8d4b\u503c\u6d41\u7a0b\uff1a<\/p>\n<ul>\n<li>\n<p>\u521b\u5efa\u521d\u59cb\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u5c5e\u6027\u5b9a\u4e49\u4e2d\u6307\u5b9a\u9ed8\u8ba4\u5c5e\u6027\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u5b9e\u4f8b\uff0c\u5e76\u8c03\u7528 init() \u65b9\u6cd5\u3002<\/p>\n<\/li>\n<\/ul>\n<hr>\n<h2>\u6784\u9020\u5668<\/h2>\n<p>\u6784\u9020\u5668\u5728\u521b\u5efa\u67d0\u7279\u5b9a\u7c7b\u578b\u7684\u65b0\u5b9e\u4f8b\u65f6\u8c03\u7528\u3002\u5b83\u7684\u6700\u7b80\u5f62\u5f0f\u7c7b\u4f3c\u4e8e\u4e00\u4e2a\u4e0d\u5e26\u4efb\u4f55\u53c2\u6570\u7684\u5b9e\u4f8b\u65b9\u6cd5\uff0c\u4ee5\u5173\u952e\u5b57init\u547d\u540d\u3002<\/p>\n<h3>\u8bed\u6cd5<\/h3>\n<pre>\ninit()\n{\n    \/\/ \u5b9e\u4f8b\u5316\u540e\u6267\u884c\u7684\u4ee3\u7801\n}\n<\/pre>\n<h3>\u5b9e\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u7ed3\u6784\u4f53\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4e0d\u5e26\u53c2\u6570\u7684\u6784\u9020\u5668 init\uff0c\u5e76\u5728\u91cc\u9762\u5c06\u5b58\u50a8\u578b\u5c5e\u6027 length \u548c breadth \u7684\u503c\u521d\u59cb\u5316\u4e3a 6 \u548c 12\uff1a\n<\/p>\n<pre>\nstruct rectangle {\n    var length: Double\n    var breadth: Double\n    init() {\n        length = 6\n        breadth = 12\n    }\n}\nvar area = rectangle()\nprint(\"\u77e9\u5f62\u9762\u79ef\u4e3a \\(area.length*area.breadth)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u77e9\u5f62\u9762\u79ef\u4e3a 72.0\n<\/pre>\n<hr>\n<h2>\u9ed8\u8ba4\u5c5e\u6027\u503c<\/h2>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u6784\u9020\u5668\u4e2d\u4e3a\u5b58\u50a8\u578b\u5c5e\u6027\u8bbe\u7f6e\u521d\u59cb\u503c\uff1b\u540c\u6837\uff0c\u4e5f\u53ef\u4ee5\u5728\u5c5e\u6027\u58f0\u660e\u65f6\u4e3a\u5176\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u3002<\/p>\n<blockquote>\n<p>\u4f7f\u7528\u9ed8\u8ba4\u503c\u80fd\u8ba9\u4f60\u7684\u6784\u9020\u5668\u66f4\u7b80\u6d01\u3001\u66f4\u6e05\u6670\uff0c\u4e14\u80fd\u901a\u8fc7\u9ed8\u8ba4\u503c\u81ea\u52a8\u63a8\u5bfc\u51fa\u5c5e\u6027\u7684\u7c7b\u578b\u3002<\/p>\n<\/blockquote>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6211\u4eec\u5728\u5c5e\u6027\u58f0\u660e\u65f6\u4e3a\u5176\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1a<\/p>\n<pre>\nstruct rectangle {\n\u00a0\u00a0\u00a0\u00a0\/\/ \u8bbe\u7f6e\u9ed8\u8ba4\u503c\n    var length = 6\n    var breadth = 12\n}\nvar area = rectangle()\nprint(\"\u77e9\u5f62\u7684\u9762\u79ef\u4e3a \\(area.length*area.breadth)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u77e9\u5f62\u9762\u79ef\u4e3a 72\n<\/pre>\n<hr>\n<h2>\u6784\u9020\u53c2\u6570<\/h2>\n<p>\u4f60\u53ef\u4ee5\u5728\u5b9a\u4e49\u6784\u9020\u5668 init() \u65f6\u63d0\u4f9b\u6784\u9020\u53c2\u6570\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>\nstruct Rectangle {\n    var length: Double\n    var breadth: Double\n    var area: Double\n    \n    init(fromLength length: Double, fromBreadth breadth: Double) {\n        self.length = length\n        self.breadth = breadth\n        area = length * breadth\n    }\n    \n    init(fromLeng leng: Double, fromBread bread: Double) {\n        self.length = leng\n        self.breadth = bread\n        area = leng * bread\n    }\n}\n\nlet ar = Rectangle(fromLength: 6, fromBreadth: 12)\nprint(\"\u9762\u79ef\u4e3a: \\(ar.area)\")\n\nlet are = Rectangle(fromLeng: 36, fromBread: 12)\nprint(\"\u9762\u79ef\u4e3a: \\(are.area)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u9762\u79ef\u4e3a: 72.0\n\u9762\u79ef\u4e3a: 432.0\n<\/pre>\n<hr>\n<h2>\u5185\u90e8\u548c\u5916\u90e8\u53c2\u6570\u540d<\/h2>\n<p>\u8ddf\u51fd\u6570\u548c\u65b9\u6cd5\u53c2\u6570\u76f8\u540c\uff0c\u6784\u9020\u53c2\u6570\u4e5f\u5b58\u5728\u4e00\u4e2a\u5728\u6784\u9020\u5668\u5185\u90e8\u4f7f\u7528\u7684\u53c2\u6570\u540d\u5b57\u548c\u4e00\u4e2a\u5728\u8c03\u7528\u6784\u9020\u5668\u65f6\u4f7f\u7528\u7684\u5916\u90e8\u53c2\u6570\u540d\u5b57\u3002<\/p>\n<p>\u7136\u800c\uff0c\u6784\u9020\u5668\u5e76\u4e0d\u50cf\u51fd\u6570\u548c\u65b9\u6cd5\u90a3\u6837\u5728\u62ec\u53f7\u524d\u6709\u4e00\u4e2a\u53ef\u8fa8\u522b\u7684\u540d\u5b57\u3002\u6240\u4ee5\u5728\u8c03\u7528\u6784\u9020\u5668\u65f6\uff0c\u4e3b\u8981\u901a\u8fc7\u6784\u9020\u5668\u4e2d\u7684\u53c2\u6570\u540d\u548c\u7c7b\u578b\u6765\u786e\u5b9a\u9700\u8981\u8c03\u7528\u7684\u6784\u9020\u5668\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5728\u5b9a\u4e49\u6784\u9020\u5668\u65f6\u6ca1\u6709\u63d0\u4f9b\u53c2\u6570\u7684\u5916\u90e8\u540d\u5b57\uff0cSwift \u4f1a\u4e3a\u6bcf\u4e2a\u6784\u9020\u5668\u7684\u53c2\u6570\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u8ddf\u5185\u90e8\u540d\u5b57\u76f8\u540c\u7684\u5916\u90e8\u540d\u3002<\/p>\n<pre>\nstruct Color {\n    let red, green, blue: Double\n    init(red: Double, green: Double, blue: Double) {\n        self.red   = red\n        self.green = green\n        self.blue  = blue\n    }\n    init(white: Double) {\n        red   = white\n        green = white\n        blue  = white\n    }\n}\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Color\u5b9e\u4f8b\uff0c\u901a\u8fc7\u4e09\u79cd\u989c\u8272\u7684\u5916\u90e8\u53c2\u6570\u540d\u6765\u4f20\u503c\uff0c\u5e76\u8c03\u7528\u6784\u9020\u5668\nlet magenta = Color(red: 1.0, green: 0.0, blue: 1.0)\n\nprint(\"red \u503c\u4e3a: \\(magenta.red)\")\nprint(\"green \u503c\u4e3a: \\(magenta.green)\")\nprint(\"blue \u503c\u4e3a: \\(magenta.blue)\")\n\n\/\/ \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Color\u5b9e\u4f8b\uff0c\u901a\u8fc7\u4e09\u79cd\u989c\u8272\u7684\u5916\u90e8\u53c2\u6570\u540d\u6765\u4f20\u503c\uff0c\u5e76\u8c03\u7528\u6784\u9020\u5668\nlet halfGray = Color(white: 0.5)\nprint(\"red \u503c\u4e3a: \\(halfGray.red)\")\nprint(\"green \u503c\u4e3a: \\(halfGray.green)\")\nprint(\"blue \u503c\u4e3a: \\(halfGray.blue)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nred \u503c\u4e3a: 1.0\ngreen \u503c\u4e3a: 0.0\nblue \u503c\u4e3a: 1.0\nred \u503c\u4e3a: 0.5\ngreen \u503c\u4e3a: 0.5\nblue \u503c\u4e3a: 0.5\n<\/pre>\n<h3>\u6ca1\u6709\u5916\u90e8\u540d\u79f0\u53c2\u6570<\/h3>\n<p>\u5982\u679c\u4f60\u4e0d\u5e0c\u671b\u4e3a\u6784\u9020\u5668\u7684\u67d0\u4e2a\u53c2\u6570\u63d0\u4f9b\u5916\u90e8\u540d\u5b57\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0b\u5212\u7ebf<code>_<\/code>\u6765\u663e\u793a\u63cf\u8ff0\u5b83\u7684\u5916\u90e8\u540d\u3002<\/p>\n<pre>\nstruct Rectangle {\n    var length: Double\n    \n    init(frombreadth breadth: Double) {\n        length = breadth * 10\n    }\n    \n    init(frombre bre: Double) {\n        length = bre * 30\n    }\n    \/\/\u4e0d\u63d0\u4f9b\u5916\u90e8\u540d\u5b57\n    init(_ area: Double) {\n        length = area\n    }\n}\n\n\/\/ \u8c03\u7528\u4e0d\u63d0\u4f9b\u5916\u90e8\u540d\u5b57\nlet rectarea = Rectangle(180.0)\nprint(\"\u9762\u79ef\u4e3a: \\(rectarea.length)\")\n\n\/\/ \u8c03\u7528\u4e0d\u63d0\u4f9b\u5916\u90e8\u540d\u5b57\nlet rearea = Rectangle(370.0)\nprint(\"\u9762\u79ef\u4e3a: \\(rearea.length)\")\n\n\/\/ \u8c03\u7528\u4e0d\u63d0\u4f9b\u5916\u90e8\u540d\u5b57\nlet recarea = Rectangle(110.0)\nprint(\"\u9762\u79ef\u4e3a: \\(recarea.length)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u9762\u79ef\u4e3a: 180.0\n\u9762\u79ef\u4e3a: 370.0\n\u9762\u79ef\u4e3a: 110.0\n<\/pre>\n<hr>\n<h2>\u53ef\u9009\u5c5e\u6027\u7c7b\u578b<\/h2>\n<p>\u5982\u679c\u4f60\u5b9a\u5236\u7684\u7c7b\u578b\u5305\u542b\u4e00\u4e2a\u903b\u8f91\u4e0a\u5141\u8bb8\u53d6\u503c\u4e3a\u7a7a\u7684\u5b58\u50a8\u578b\u5c5e\u6027\uff0c\u4f60\u90fd\u9700\u8981\u5c06\u5b83\u5b9a\u4e49\u4e3a\u53ef\u9009\u7c7b\u578boptional type\uff08\u53ef\u9009\u5c5e\u6027\u7c7b\u578b\uff09\u3002<\/p>\n<p>\u5f53\u5b58\u50a8\u5c5e\u6027\u58f0\u660e\u4e3a\u53ef\u9009\u65f6\uff0c\u5c06\u81ea\u52a8\u521d\u59cb\u5316\u4e3a\u7a7a nil\u3002<\/p>\n<pre>\nstruct Rectangle {\n    var length: Double?\n    \n    init(frombreadth breadth: Double) {\n        length = breadth * 10\n    }\n    \n    init(frombre bre: Double) {\n        length = bre * 30\n    }\n    \n    init(_ area: Double) {\n        length = area\n    }\n}\n\nlet rectarea = Rectangle(180.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(rectarea.length)\")\n\nlet rearea = Rectangle(370.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(rearea.length)\")\n\nlet recarea = Rectangle(110.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(recarea.length)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u9762\u79ef\u4e3a\uff1aOptional(180.0)\n\u9762\u79ef\u4e3a\uff1aOptional(370.0)\n\u9762\u79ef\u4e3a\uff1aOptional(110.0)\n<\/pre>\n<hr>\n<h2>\u6784\u9020\u8fc7\u7a0b\u4e2d\u4fee\u6539\u5e38\u91cf\u5c5e\u6027<\/h2>\n<p>\u53ea\u8981\u5728\u6784\u9020\u8fc7\u7a0b\u7ed3\u675f\u524d\u5e38\u91cf\u7684\u503c\u80fd\u786e\u5b9a\uff0c\u4f60\u53ef\u4ee5\u5728\u6784\u9020\u8fc7\u7a0b\u4e2d\u7684\u4efb\u610f\u65f6\u95f4\u70b9\u4fee\u6539\u5e38\u91cf\u5c5e\u6027\u7684\u503c\u3002<\/p>\n<p>\u5bf9\u67d0\u4e2a\u7c7b\u5b9e\u4f8b\u6765\u8bf4\uff0c\u5b83\u7684\u5e38\u91cf\u5c5e\u6027\u53ea\u80fd\u5728\u5b9a\u4e49\u5b83\u7684\u7c7b\u7684\u6784\u9020\u8fc7\u7a0b\u4e2d\u4fee\u6539\uff1b\u4e0d\u80fd\u5728\u5b50\u7c7b\u4e2d\u4fee\u6539\u3002<\/p>\n<p>\u5c3d\u7ba1 length \u5c5e\u6027\u73b0\u5728\u662f\u5e38\u91cf\uff0c\u6211\u4eec\u4ecd\u7136\u53ef\u4ee5\u5728\u5176\u7c7b\u7684\u6784\u9020\u5668\u4e2d\u8bbe\u7f6e\u5b83\u7684\u503c\uff1a<\/p>\n<pre>\nstruct Rectangle {\n    let length: Double?\n    \n    init(frombreadth breadth: Double) {\n        length = breadth * 10\n    }\n    \n    init(frombre bre: Double) {\n        length = bre * 30\n    }\n    \n    init(_ area: Double) {\n        length = area\n    }\n}\n\nlet rectarea = Rectangle(180.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(rectarea.length)\")\n\nlet rearea = Rectangle(370.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(rearea.length)\")\n\nlet recarea = Rectangle(110.0)\nprint(\"\u9762\u79ef\u4e3a\uff1a\\(recarea.length)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u9762\u79ef\u4e3a\uff1aOptional(180.0)\n\u9762\u79ef\u4e3a\uff1aOptional(370.0)\n\u9762\u79ef\u4e3a\uff1aOptional(110.0)\n<\/pre>\n<hr>\n<h2>\u9ed8\u8ba4\u6784\u9020\u5668<\/h2>\n<p>\u9ed8\u8ba4\u6784\u9020\u5668\u5c06\u7b80\u5355\u7684\u521b\u5efa\u4e00\u4e2a\u6240\u6709\u5c5e\u6027\u503c\u90fd\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503c\u7684\u5b9e\u4f8b:<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u4e2d\uff0cShoppingListItem\u7c7b\u4e2d\u7684\u6240\u6709\u5c5e\u6027\u90fd\u6709\u9ed8\u8ba4\u503c\uff0c\u4e14\u5b83\u662f\u6ca1\u6709\u7236\u7c7b\u7684\u57fa\u7c7b\uff0c\u5b83\u5c06\u81ea\u52a8\u83b7\u5f97\u4e00\u4e2a\u53ef\u4ee5\u4e3a\u6240\u6709\u5c5e\u6027\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u7684\u9ed8\u8ba4\u6784\u9020\u5668\n<\/p>\n<pre>\nclass ShoppingListItem {\n    var name: String?\n    var quantity = 1\n    var purchased = false\n}\nvar item = ShoppingListItem()\n\n\nprint(\"\u540d\u5b57\u4e3a: \\(item.name)\")\nprint(\"\u6570\u7406\u4e3a: \\(item.quantity)\")\nprint(\"\u662f\u5426\u4ed8\u6b3e: \\(item.purchased)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\u540d\u5b57\u4e3a: nil\n\u6570\u7406\u4e3a: 1\n\u662f\u5426\u4ed8\u6b3e: false\n<\/pre>\n<p>\u7ed3\u6784\u4f53\u7684\u9010\u4e00\u6210\u5458\u6784\u9020\u5668<\/p>\n<p>\u5982\u679c\u7ed3\u6784\u4f53\u5bf9\u6240\u6709\u5b58\u50a8\u578b\u5c5e\u6027\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u503c\u4e14\u81ea\u8eab\u6ca1\u6709\u63d0\u4f9b\u5b9a\u5236\u7684\u6784\u9020\u5668\uff0c\u5b83\u4eec\u80fd\u81ea\u52a8\u83b7\u5f97\u4e00\u4e2a\u9010\u4e00\u6210\u5458\u6784\u9020\u5668\u3002<\/p>\n<p>\u6211\u4eec\u5728\u8c03\u7528\u9010\u4e00\u6210\u5458\u6784\u9020\u5668\u65f6\uff0c\u901a\u8fc7\u4e0e\u6210\u5458\u5c5e\u6027\u540d\u76f8\u540c\u7684\u53c2\u6570\u540d\u8fdb\u884c\u4f20\u503c\u6765\u5b8c\u6210\u5bf9\u6210\u5458\u5c5e\u6027\u7684\u521d\u59cb\u8d4b\u503c\u3002<\/p>\n<p>\n\u4e0b\u9762\u4f8b\u5b50\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7ed3\u6784\u4f53 Rectangle\uff0c\u5b83\u5305\u542b\u4e24\u4e2a\u5c5e\u6027 length \u548c breadth\u3002Swift \u53ef\u4ee5\u6839\u636e\u8fd9\u4e24\u4e2a\u5c5e\u6027\u7684\u521d\u59cb\u8d4b\u503c100.0 \u3001200.0\u81ea\u52a8\u63a8\u5bfc\u51fa\u5b83\u4eec\u7684\u7c7b\u578bDouble\u3002<\/p>\n<pre>\nstruct Rectangle {\n    var length = 100.0, breadth = 200.0\n}\nlet area = Rectangle(length: 24.0, breadth: 32.0)\n\nprint(\"\u77e9\u5f62\u7684\u9762\u79ef: \\(area.length)\")\nprint(\"\u77e9\u5f62\u7684\u9762\u79ef: \\(area.breadth)\")\n<\/pre>\n<p>\n\u7531\u4e8e\u8fd9\u4e24\u4e2a\u5b58\u50a8\u578b\u5c5e\u6027\u90fd\u6709\u9ed8\u8ba4\u503c\uff0c\u7ed3\u6784\u4f53 Rectangle \u81ea\u52a8\u83b7\u5f97\u4e86\u4e00\u4e2a\u9010\u4e00\u6210\u5458\u6784\u9020\u5668 init(width:height:)\u3002 \u4f60\u53ef\u4ee5\u7528\u5b83\u6765\u4e3a Rectangle \u521b\u5efa\u65b0\u7684\u5b9e\u4f8b\u3002\n<\/p>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\u540d\u5b57\u4e3a: nil\n\u77e9\u5f62\u7684\u9762\u79ef: 24.0\n\u77e9\u5f62\u7684\u9762\u79ef: 32.0\n<\/pre>\n<hr>\n<h2>\u503c\u7c7b\u578b\u7684\u6784\u9020\u5668\u4ee3\u7406<\/h2>\n<p>\u6784\u9020\u5668\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u5176\u5b83\u6784\u9020\u5668\u6765\u5b8c\u6210\u5b9e\u4f8b\u7684\u90e8\u5206\u6784\u9020\u8fc7\u7a0b\u3002\u8fd9\u4e00\u8fc7\u7a0b\u79f0\u4e3a\u6784\u9020\u5668\u4ee3\u7406\uff0c\u5b83\u80fd\u51cf\u5c11\u591a\u4e2a\u6784\u9020\u5668\u95f4\u7684\u4ee3\u7801\u91cd\u590d\u3002<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u4e2d\uff0cRect \u7ed3\u6784\u4f53\u8c03\u7528\u4e86 Size \u548c Point \u7684\u6784\u9020\u8fc7\u7a0b\uff1a<\/p>\n<pre>\nstruct Size {\n    var width = 0.0, height = 0.0\n}\nstruct Point {\n    var x = 0.0, y = 0.0\n}\n\nstruct Rect {\n    var origin = Point()\n    var size = Size()\n    init() {}\n    init(origin: Point, size: Size) {\n        self.origin = origin\n        self.size = size\n    }\n    init(center: Point, size: Size) {\n        let originX = center.x - (size.width \/ 2)\n        let originY = center.y - (size.height \/ 2)\n        self.init(origin: Point(x: originX, y: originY), size: size)\n    }\n}\n\n\n\/\/ origin\u548csize\u5c5e\u6027\u90fd\u4f7f\u7528\u5b9a\u4e49\u65f6\u7684\u9ed8\u8ba4\u503cPoint(x: 0.0, y: 0.0)\u548cSize(width: 0.0, height: 0.0)\uff1a\nlet basicRect = Rect()\nprint(\"Size \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(basicRect.size.width, basicRect.size.height) \")\nprint(\"Rect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(basicRect.origin.x, basicRect.origin.y) \")\n\n\/\/ \u5c06origin\u548csize\u7684\u53c2\u6570\u503c\u8d4b\u7ed9\u5bf9\u5e94\u7684\u5b58\u50a8\u578b\u5c5e\u6027\nlet originRect = Rect(origin: Point(x: 2.0, y: 2.0),\n    size: Size(width: 5.0, height: 5.0))\n\nprint(\"Size \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(originRect.size.width, originRect.size.height) \")\nprint(\"Rect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(originRect.origin.x, originRect.origin.y) \")\n\n\n\/\/\u5148\u901a\u8fc7center\u548csize\u7684\u503c\u8ba1\u7b97\u51faorigin\u7684\u5750\u6807\u3002\n\/\/\u7136\u540e\u518d\u8c03\u7528\uff08\u6216\u4ee3\u7406\u7ed9\uff09init(origin:size:)\u6784\u9020\u5668\u6765\u5c06\u65b0\u7684origin\u548csize\u503c\u8d4b\u503c\u5230\u5bf9\u5e94\u7684\u5c5e\u6027\u4e2d\nlet centerRect = Rect(center: Point(x: 4.0, y: 4.0),\n    size: Size(width: 3.0, height: 3.0))\n\nprint(\"Size \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(centerRect.size.width, centerRect.size.height) \")\nprint(\"Rect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: \\(centerRect.origin.x, centerRect.origin.y) \")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nSize \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (0.0, 0.0) \nRect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (0.0, 0.0) \nSize \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (5.0, 5.0) \nRect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (2.0, 2.0) \nSize \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (3.0, 3.0) \nRect \u7ed3\u6784\u4f53\u521d\u59cb\u503c: (2.5, 2.5) \n<\/pre>\n<h3>\u6784\u9020\u5668\u4ee3\u7406\u89c4\u5219<\/h3>\n<table class=\"reference\">\n<tbody>\n<tr>\n<th>\u503c\u7c7b\u578b<\/th>\n<th>\u7c7b\u7c7b\u578b<\/th>\n<\/tr>\n<tr>\n<td>\u4e0d\u652f\u6301\u7ee7\u627f\uff0c\u6240\u4ee5\u6784\u9020\u5668\u4ee3\u7406\u7684\u8fc7\u7a0b\u76f8\u5bf9\u7b80\u5355\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u80fd\u4ee3\u7406\u7ed9\u672c\u8eab\u63d0\u4f9b\u7684\u5176\u5b83\u6784\u9020\u5668\u3002<br \/>\n\u4f60\u53ef\u4ee5\u4f7f\u7528self.init\u5728\u81ea\u5b9a\u4e49\u7684\u6784\u9020\u5668\u4e2d\u5f15\u7528\u5176\u5b83\u7684\u5c5e\u4e8e\u76f8\u540c\u503c\u7c7b\u578b\u7684\u6784\u9020\u5668\u3002<\/td>\n<td>\u5b83\u53ef\u4ee5\u7ee7\u627f\u81ea\u5176\u5b83\u7c7b,\u8fd9\u610f\u5473\u7740\u7c7b\u6709\u8d23\u4efb\u4fdd\u8bc1\u5176\u6240\u6709\u7ee7\u627f\u7684\u5b58\u50a8\u578b\u5c5e\u6027\u5728\u6784\u9020\u65f6\u4e5f\u80fd\u6b63\u786e\u7684\u521d\u59cb\u5316\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2>\u7c7b\u7684\u7ee7\u627f\u548c\u6784\u9020\u8fc7\u7a0b<\/h2>\n<p>Swift \u63d0\u4f9b\u4e86\u4e24\u79cd\u7c7b\u578b\u7684\u7c7b\u6784\u9020\u5668\u6765\u786e\u4fdd\u6240\u6709\u7c7b\u5b9e\u4f8b\u4e2d\u5b58\u50a8\u578b\u5c5e\u6027\u90fd\u80fd\u83b7\u5f97\u521d\u59cb\u503c\uff0c\u5b83\u4eec\u5206\u522b\u662f\u6307\u5b9a\u6784\u9020\u5668\u548c\u4fbf\u5229\u6784\u9020\u5668\u3002<\/p>\n<table class=\"reference\">\n<tbody>\n<tr>\n<td>\u6307\u5b9a\u6784\u9020\u5668<\/td>\n<td>\u4fbf\u5229\u6784\u9020\u5668<\/td>\n<\/tr>\n<tr>\n<td>\u7c7b\u4e2d\u6700\u4e3b\u8981\u7684\u6784\u9020\u5668<\/td>\n<td>\u7c7b\u4e2d\u6bd4\u8f83\u6b21\u8981\u7684\u3001\u8f85\u52a9\u578b\u7684\u6784\u9020\u5668<\/td>\n<\/tr>\n<tr>\n<td>\u521d\u59cb\u5316\u7c7b\u4e2d\u63d0\u4f9b\u7684\u6240\u6709\u5c5e\u6027\uff0c\u5e76\u6839\u636e\u7236\u7c7b\u94fe\u5f80\u4e0a\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u5668\u6765\u5b9e\u73b0\u7236\u7c7b\u7684\u521d\u59cb\u5316\u3002<\/td>\n<td>\u53ef\u4ee5\u5b9a\u4e49\u4fbf\u5229\u6784\u9020\u5668\u6765\u8c03\u7528\u540c\u4e00\u4e2a\u7c7b\u4e2d\u7684\u6307\u5b9a\u6784\u9020\u5668\uff0c\u5e76\u4e3a\u5176\u53c2\u6570\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002\u4f60\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u4fbf\u5229\u6784\u9020\u5668\u6765\u521b\u5efa\u4e00\u4e2a\u7279\u6b8a\u7528\u9014\u6216\u7279\u5b9a\u8f93\u5165\u7684\u5b9e\u4f8b\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6bcf\u4e00\u4e2a\u7c7b\u90fd\u5fc5\u987b\u62e5\u6709\u81f3\u5c11\u4e00\u4e2a\u6307\u5b9a\u6784\u9020\u5668<\/td>\n<td>\u53ea\u5728\u5fc5\u8981\u7684\u65f6\u5019\u4e3a\u7c7b\u63d0\u4f9b\u4fbf\u5229\u6784\u9020\u5668<\/td>\n<\/tr>\n<tr>\n<td>\n<pre>\nInit(parameters) {\n    statements\n}\n<\/pre>\n<\/td>\n<td>\n<pre>\nconvenience init(parameters) {\n      statements\n}\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u6307\u5b9a\u6784\u9020\u5668\u5b9e\u4f8b<\/h3>\n<pre>\nclass mainClass {\n    var no1 : Int \/\/ \u5c40\u90e8\u5b58\u50a8\u53d8\u91cf\n    init(no1 : Int) {\n        self.no1 = no1 \/\/ \u521d\u59cb\u5316\n    }\n}\nclass subClass : mainClass {\n    var no2 : Int \/\/ \u65b0\u7684\u5b50\u7c7b\u5b58\u50a8\u53d8\u91cf\n    init(no1 : Int, no2 : Int) {\n        self.no2 = no2 \/\/ \u521d\u59cb\u5316\n        super.init(no1:no1) \/\/ \u521d\u59cb\u5316\u8d85\u7c7b\n    }\n}\n\nlet res = mainClass(no1: 10)\nlet res2 = subClass(no1: 10, no2: 20)\n\nprint(\"res \u4e3a: \\(res.no1)\")\nprint(\"res2 \u4e3a: \\(res2.no1)\")\nprint(\"res2 \u4e3a: \\(res2.no2)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>res \u4e3a: 10\nres \u4e3a: 10\nres \u4e3a: 20\n<\/pre>\n<h3>\u4fbf\u5229\u6784\u9020\u5668\u5b9e\u4f8b<\/h3>\n<pre>\nclass mainClass {\n    var no1 : Int \/\/ \u5c40\u90e8\u5b58\u50a8\u53d8\u91cf\n    init(no1 : Int) {\n        self.no1 = no1 \/\/ \u521d\u59cb\u5316\n    }\n}\n\nclass subClass : mainClass {\n    var no2 : Int\n    init(no1 : Int, no2 : Int) {\n        self.no2 = no2\n        super.init(no1:no1)\n    }\n    \/\/ \u4fbf\u5229\u65b9\u6cd5\u53ea\u9700\u8981\u4e00\u4e2a\u53c2\u6570\n    override convenience init(no1: Int)  {\n        self.init(no1:no1, no2:0)\n    }\n}\nlet res = mainClass(no1: 20)\nlet res2 = subClass(no1: 30, no2: 50)\n\nprint(\"res \u4e3a: \\(res.no1)\")\nprint(\"res2 \u4e3a: \\(res2.no1)\")\nprint(\"res2 \u4e3a: \\(res2.no2)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nres \u4e3a: 20\nres2 \u4e3a: 30\nres2 \u4e3a: 50\n<\/pre>\n<hr>\n<h2>\u6784\u9020\u5668\u7684\u7ee7\u627f\u548c\u91cd\u8f7d<\/h2>\n<p>Swift \u4e2d\u7684\u5b50\u7c7b\u4e0d\u4f1a\u9ed8\u8ba4\u7ee7\u627f\u7236\u7c7b\u7684\u6784\u9020\u5668\u3002<\/p>\n<p>\u7236\u7c7b\u7684\u6784\u9020\u5668\u4ec5\u5728\u786e\u5b9a\u548c\u5b89\u5168\u7684\u60c5\u51b5\u4e0b\u88ab\u7ee7\u627f\u3002<\/p>\n<p>\u5f53\u4f60\u91cd\u5199\u4e00\u4e2a\u7236\u7c7b\u6307\u5b9a\u6784\u9020\u5668\u65f6\uff0c\u4f60\u9700\u8981\u5199override\u4fee\u9970\u7b26\u3002<\/p>\n<pre>\nclass SuperClass {\n    var corners = 4\n    var description: String {\n        return \"\\(corners) \u8fb9\"\n    }\n}\nlet rectangle = SuperClass()\nprint(\"\u77e9\u5f62: \\(rectangle.description)\")\n\nclass SubClass: SuperClass {\n    override init() {  \/\/\u91cd\u8f7d\u6784\u9020\u5668\n        super.init()\n        corners = 5\n    }\n}\n\nlet subClass = SubClass()\nprint(\"\u4e94\u89d2\u578b: \\(subClass.description)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u77e9\u5f62: 4 \u8fb9\n\u4e94\u89d2\u578b: 5 \u8fb9\n<\/pre>\n<h3>\u6307\u5b9a\u6784\u9020\u5668\u548c\u4fbf\u5229\u6784\u9020\u5668\u5b9e\u4f8b<\/h3>\n<p>\n\u63a5\u4e0b\u6765\u7684\u4f8b\u5b50\u5c06\u5728\u64cd\u4f5c\u4e2d\u5c55\u793a\u6307\u5b9a\u6784\u9020\u5668\u3001\u4fbf\u5229\u6784\u9020\u5668\u548c\u81ea\u52a8\u6784\u9020\u5668\u7684\u7ee7\u627f\u3002<\/p>\n<p>\u5b83\u5b9a\u4e49\u4e86\u5305\u542b\u4e24\u4e2a\u4e2a\u7c7bMainClass\u3001SubClass\u7684\u7c7b\u5c42\u6b21\u7ed3\u6784\uff0c\u5e76\u5c06\u6f14\u793a\u5b83\u4eec\u7684\u6784\u9020\u5668\u662f\u5982\u4f55\u76f8\u4e92\u4f5c\u7528\u7684\u3002\n<\/p>\n<pre>\nclass MainClass {\n    var name: String\n    \n    init(name: String) {\n        self.name = name\n    }\n    \n    convenience init() {\n        self.init(name: \"[\u533f\u540d]\")\n    }\n}\nlet main = MainClass(name: \"Runoob\")\nprint(\"MainClass \u540d\u5b57\u4e3a: \\(main.name)\")\n\nlet main2 = MainClass()\nprint(\"\u6ca1\u6709\u5bf9\u5e94\u540d\u5b57: \\(main2.name)\")\n\nclass SubClass: MainClass {\n    var count: Int\n    init(name: String, count: Int) {\n        self.count = count\n        super.init(name: name)\n    }\n    \n    override convenience init(name: String) {\n        self.init(name: name, count: 1)\n    }\n}\n\nlet sub = SubClass(name: \"Runoob\")\nprint(\"MainClass \u540d\u5b57\u4e3a: \\(sub.name)\")\n\nlet sub2 = SubClass(name: \"Runoob\", count: 3)\nprint(\"count \u53d8\u91cf: \\(sub2.count)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nMainClass \u540d\u5b57\u4e3a: Runoob\n\u6ca1\u6709\u5bf9\u5e94\u540d\u5b57: [\u533f\u540d]\nMainClass \u540d\u5b57\u4e3a: Runoob\ncount \u53d8\u91cf: 3\n<\/pre>\n<hr>\n<h2>\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668<\/h2>\n<p>\n\u5982\u679c\u4e00\u4e2a\u7c7b\uff0c\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u5728\u6784\u9020\u81ea\u8eab\u7684\u8fc7\u7a0b\u4e2d\u6709\u53ef\u80fd\u5931\u8d25\uff0c\u5219\u4e3a\u5176\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002<\/p>\n<p>\u53d8\u91cf\u521d\u59cb\u5316\u5931\u8d25\u53ef\u80fd\u7684\u539f\u56e0\u6709\uff1a<\/p>\n<ul>\n<li>\n<p>\u4f20\u5165\u65e0\u6548\u7684\u53c2\u6570\u503c\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f3a\u5c11\u67d0\u79cd\u6240\u9700\u7684\u5916\u90e8\u8d44\u6e90\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ca1\u6709\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e3a\u4e86\u59a5\u5584\u5904\u7406\u8fd9\u79cd\u6784\u9020\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u5931\u8d25\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u5728\u4e00\u4e2a\u7c7b\uff0c\u7ed3\u6784\u4f53\u6216\u662f\u679a\u4e3e\u7c7b\u578b\u7684\u5b9a\u4e49\u4e2d\uff0c\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002\u5176\u8bed\u6cd5\u4e3a\u5728init\u5173\u952e\u5b57\u540e\u9762\u52a0\u6dfb\u95ee\u53f7(init?)\u3002<\/p>\n<h3>\u5b9e\u4f8b<\/h3>\n<p>\u4e0b\u4f8b\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3aAnimal\u7684\u7ed3\u6784\u4f53\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u540d\u4e3aspecies\u7684\uff0cString\u7c7b\u578b\u7684\u5e38\u91cf\u5c5e\u6027\u3002<\/p>\n<p>\u540c\u65f6\u8be5\u7ed3\u6784\u4f53\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\uff0c\u5e26\u4e00\u4e2aString\u7c7b\u578b\u53c2\u6570species\u7684,\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002\u8fd9\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\uff0c\u88ab\u7528\u6765\u68c0\u67e5\u4f20\u5165\u7684\u53c2\u6570\u662f\u5426\u4e3a\u4e00\u4e2a\u7a7a\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u4e3a\u7a7a\u5b57\u7b26\u4e32\uff0c\u5219\u8be5\u53ef\u5931\u8d25\u6784\u9020\u5668\uff0c\u6784\u5efa\u5bf9\u8c61\u5931\u8d25\uff0c\u5426\u5219\u6210\u529f\u3002<\/p>\n<pre>\nstruct Animal {\n    let species: String\n    init?(species: String) {\n        if species.isEmpty { return nil }\n        self.species = species\n    }\n}\n\n\/\/\u901a\u8fc7\u8be5\u53ef\u5931\u8d25\u6784\u9020\u5668\u6765\u6784\u5efa\u4e00\u4e2aAnimal\u7684\u5bf9\u8c61\uff0c\u5e76\u68c0\u67e5\u5176\u6784\u5efa\u8fc7\u7a0b\u662f\u5426\u6210\u529f\n\/\/ someCreature \u7684\u7c7b\u578b\u662f Animal? \u800c\u4e0d\u662f Animal\nlet someCreature = Animal(species: \"\u957f\u9888\u9e7f\")\n\n\/\/ \u6253\u5370 \"\u52a8\u7269\u521d\u59cb\u5316\u4e3a\u957f\u9888\u9e7f\"\nif let giraffe = someCreature {\n    print(\"\u52a8\u7269\u521d\u59cb\u5316\u4e3a\\(giraffe.species)\")\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u52a8\u7269\u521d\u59cb\u5316\u4e3a\u957f\u9888\u9e7f\n<\/pre>\n<h3>\u679a\u4e3e\u7c7b\u578b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668<\/h3>\n<p>\u4f60\u53ef\u4ee5\u901a\u8fc7\u6784\u9020\u4e00\u4e2a\u5e26\u4e00\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\u6765\u83b7\u53d6\u679a\u4e3e\u7c7b\u578b\u4e2d\u7279\u5b9a\u7684\u679a\u4e3e\u6210\u5458\u3002<\/p>\n<h3>\u5b9e\u4f8b<\/h3>\n<p>\n\u4e0b\u4f8b\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3aTemperatureUnit\u7684\u679a\u4e3e\u7c7b\u578b\u3002\u5176\u4e2d\u5305\u542b\u4e86\u4e09\u4e2a\u53ef\u80fd\u7684\u679a\u4e3e\u6210\u5458(Kelvin\uff0cCelsius\uff0c\u548c Fahrenheit)\u548c\u4e00\u4e2a\u88ab\u7528\u6765\u627e\u5230Character\u503c\u6240\u5bf9\u5e94\u7684\u679a\u4e3e\u6210\u5458\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\uff1a<\/p>\n<pre>\nenum TemperatureUnit {\n\u00a0\u00a0\u00a0\u00a0\/\/ \u5f00\u5c14\u6587\uff0c\u6444\u6c0f\uff0c\u534e\u6c0f\n    case Kelvin, Celsius, Fahrenheit\n    init?(symbol: Character) {\n        switch symbol {\n        case \"K\":\n            self = .Kelvin\n        case \"C\":\n            self = .Celsius\n        case \"F\":\n            self = .Fahrenheit\n        default:\n            return nil\n        }\n    }\n}\n\n\nlet fahrenheitUnit = TemperatureUnit(symbol: \"F\")\nif fahrenheitUnit != nil {\n    print(\"\u8fd9\u662f\u4e00\u4e2a\u5df2\u5b9a\u4e49\u7684\u6e29\u5ea6\u5355\u4f4d\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u6210\u529f\u3002\")\n}\n\nlet unknownUnit = TemperatureUnit(symbol: \"X\")\nif unknownUnit == nil {\n    print(\"\u8fd9\u4e0d\u662f\u4e00\u4e2a\u5df2\u5b9a\u4e49\u7684\u6e29\u5ea6\u5355\u4f4d\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u5931\u8d25\u3002\")\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u8fd9\u662f\u4e00\u4e2a\u5df2\u5b9a\u4e49\u7684\u6e29\u5ea6\u5355\u4f4d\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u6210\u529f\u3002\n\u8fd9\u4e0d\u662f\u4e00\u4e2a\u5df2\u5b9a\u4e49\u7684\u6e29\u5ea6\u5355\u4f4d\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u5931\u8d25\u3002\n<\/pre>\n<hr>\n<h2>\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668<\/h2>\n<p>\u503c\u7c7b\u578b\uff08\u5982\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\uff09\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\uff0c\u5bf9\u4f55\u65f6\u4f55\u5730\u89e6\u53d1\u6784\u9020\u5931\u8d25\u8fd9\u4e2a\u884c\u4e3a\u6ca1\u6709\u4efb\u4f55\u7684\u9650\u5236\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\u53ea\u80fd\u5728\u6240\u6709\u7684\u7c7b\u5c5e\u6027\u88ab\u521d\u59cb\u5316\u540e\u548c\u6240\u6709\u7c7b\u4e4b\u95f4\u7684\u6784\u9020\u5668\u4e4b\u95f4\u7684\u4ee3\u7406\u8c03\u7528\u53d1\u751f\u5b8c\u540e\u89e6\u53d1\u5931\u8d25\u884c\u4e3a\u3002<\/p>\n<h3>\u5b9e\u4f8b<\/h3>\n<p>\u4e0b\u4f8b\u5b50\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a StudRecord \u7684\u7c7b\uff0c\u56e0\u4e3a studname \u5c5e\u6027\u662f\u4e00\u4e2a\u5e38\u91cf\uff0c\u6240\u4ee5\u4e00\u65e6 StudRecord \u7c7b\u6784\u9020\u6210\u529f\uff0cstudname \u5c5e\u6027\u80af\u5b9a\u6709\u4e00\u4e2a\u975enil\u7684\u503c\u3002<\/p>\n<pre>\nclass StudRecord {\n    let studname: String!\n    init?(studname: String) {\n        self.studname = studname\n        if studname.isEmpty { return nil }\n    }\n}\nif let stname = StudRecord(studname: \"\u5931\u8d25\u6784\u9020\u5668\") {\n    print(\"\u6a21\u5757\u4e3a \\(stname.studname)\")\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u6a21\u5757\u4e3a \u5931\u8d25\u6784\u9020\u5668\n<\/pre>\n<hr>\n<h2>\u8986\u76d6\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668<\/h2>\n<p>\u5c31\u5982\u540c\u5176\u5b83\u6784\u9020\u5668\u4e00\u6837\uff0c\u4f60\u4e5f\u53ef\u4ee5\u7528\u5b50\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\u8986\u76d6\u57fa\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002<\/p>\n<p>\u8005\u4f60\u4e5f\u53ef\u4ee5\u7528\u5b50\u7c7b\u7684\u975e\u53ef\u5931\u8d25\u6784\u9020\u5668\u8986\u76d6\u4e00\u4e2a\u57fa\u7c7b\u7684\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u7528\u4e00\u4e2a\u975e\u53ef\u5931\u8d25\u6784\u9020\u5668\u8986\u76d6\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\uff0c\u4f46\u53cd\u8fc7\u6765\u5374\u884c\u4e0d\u901a\u3002<\/p>\n<p>\u4e00\u4e2a\u975e\u53ef\u5931\u8d25\u7684\u6784\u9020\u5668\u6c38\u8fdc\u4e5f\u4e0d\u80fd\u4ee3\u7406\u8c03\u7528\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\u3002<\/p>\n<h3>\u5b9e\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u63cf\u8ff0\u4e86\u53ef\u5931\u8d25\u4e0e\u975e\u53ef\u5931\u8d25\u6784\u9020\u5668\uff1a<\/p>\n<pre>\nclass Planet {\n    var name: String\n    \n    init(name: String) {\n        self.name = name\n    }\n    \n    convenience init() {\n        self.init(name: \"[No Planets]\")\n    }\n}\nlet plName = Planet(name: \"Mercury\")\nprint(\"\u884c\u661f\u7684\u540d\u5b57\u662f: \\(plName.name)\")\n\nlet noplName = Planet()\nprint(\"\u6ca1\u6709\u8fd9\u4e2a\u540d\u5b57\u7684\u884c\u661f: \\(noplName.name)\")\n\nclass planets: Planet {\n    var count: Int\n    \n    init(name: String, count: Int) {\n        self.count = count\n        super.init(name: name)\n    }\n    \n    override convenience init(name: String) {\n        self.init(name: name, count: 1)\n    }\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u884c\u661f\u7684\u540d\u5b57\u662f: Mercury\n\u6ca1\u6709\u8fd9\u4e2a\u540d\u5b57\u7684\u884c\u661f: [No Planets]\n<\/pre>\n<hr>\n<h2>\u53ef\u5931\u8d25\u6784\u9020\u5668 init!<\/h2>\n<p>\u901a\u5e38\u6765\u8bf4\u6211\u4eec\u901a\u8fc7\u5728init\u5173\u952e\u5b57\u540e\u6dfb\u52a0\u95ee\u53f7\u7684\u65b9\u5f0f\uff08init?\uff09\u6765\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668\uff0c\u4f46\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u901a\u8fc7\u5728init\u540e\u9762\u6dfb\u52a0\u60ca\u53f9\u53f7\u7684\u65b9\u5f0f\u6765\u5b9a\u4e49\u4e00\u4e2a\u53ef\u5931\u8d25\u6784\u9020\u5668(init!)\u3002\u5b9e\u4f8b\u5982\u4e0b\uff1a\n<\/p>\n<pre>\nstruct StudRecord {\n    let stname: String\n    \n    init!(stname: String) {\n        if stname.isEmpty {return nil }\n        self.stname = stname\n    }\n}\n\nlet stmark = StudRecord(stname: \"Runoob\")\nif let name = stmark {\n    print(\"\u6307\u5b9a\u4e86\u5b66\u751f\u540d\")\n}\n\nlet blankname = StudRecord(stname: \"\")\nif blankname == nil {\n    print(\"\u5b66\u751f\u540d\u4e3a\u7a7a\")\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u6307\u5b9a\u4e86\u5b66\u751f\u540d\n\u5b66\u751f\u540d\u4e3a\u7a7a\n<\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift \u6784\u9020\u8fc7\u7a0b \u6784\u9020\u8fc7\u7a0b\u662f\u4e3a\u4e86\u4f7f\u7528\u67d0\u4e2a\u7c7b\u3001\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\u7684\u5b9e\u4f8b\u800c\u8fdb\u884c\u7684\u51c6\u5907\u8fc7\u7a0b\u3002\u8fd9&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=542\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,28],"tags":[74,119],"class_list":["post-542","post","type-post","status-publish","format-standard","hentry","category-mobile","category-swift","tag-ios","tag-swift","zoom-theme-has-thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.puzi7.net\/?p=542\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7\" \/>\n<meta property=\"og:description\" content=\"Swift \u6784\u9020\u8fc7\u7a0b \u6784\u9020\u8fc7\u7a0b\u662f\u4e3a\u4e86\u4f7f\u7528\u67d0\u4e2a\u7c7b\u3001\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\u7684\u5b9e\u4f8b\u800c\u8fdb\u884c\u7684\u51c6\u5907\u8fc7\u7a0b\u3002\u8fd9&hellip;Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.puzi7.net\/?p=542\" \/>\n<meta property=\"og:site_name\" content=\"\u8c31\u5b50\u68cb - Puzi7\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-23T15:39:07+00:00\" \/>\n<meta name=\"author\" content=\"\u77f3\u8863\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u77f3\u8863\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542\"},\"author\":{\"name\":\"\u77f3\u8863\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/#\\\/schema\\\/person\\\/87dd4941c8ec260c1350b7f41980a190\"},\"headline\":\"Swift \u6784\u9020\u8fc7\u7a0b\",\"datePublished\":\"2018-02-23T15:39:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542\"},\"wordCount\":61,\"commentCount\":0,\"keywords\":[\"iOS\",\"Swift\"],\"articleSection\":[\"Mobile\",\"Swift\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.puzi7.net\\\/?p=542#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542\",\"url\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542\",\"name\":\"Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/#website\"},\"datePublished\":\"2018-02-23T15:39:07+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/#\\\/schema\\\/person\\\/87dd4941c8ec260c1350b7f41980a190\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.puzi7.net\\\/?p=542\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/?p=542#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/www.puzi7.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6280\u672f\",\"item\":\"https:\\\/\\\/www.puzi7.net\\\/?cat=9\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Mobile\",\"item\":\"https:\\\/\\\/www.puzi7.net\\\/?cat=26\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Swift\",\"item\":\"https:\\\/\\\/www.puzi7.net\\\/?cat=28\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Swift \u6784\u9020\u8fc7\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/#website\",\"url\":\"https:\\\/\\\/www.puzi7.net\\\/\",\"name\":\"\u8c31\u5b50\u68cb - Puzi7\",\"description\":\"\u5206\u4eab\uff0c\u6210\u957f\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.puzi7.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.puzi7.net\\\/#\\\/schema\\\/person\\\/87dd4941c8ec260c1350b7f41980a190\",\"name\":\"\u77f3\u8863\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g\",\"caption\":\"\u77f3\u8863\"},\"sameAs\":[\"https:\\\/\\\/www.puzi7.net\"],\"url\":\"https:\\\/\\\/www.puzi7.net\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.puzi7.net\/?p=542","og_locale":"zh_CN","og_type":"article","og_title":"Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7","og_description":"Swift \u6784\u9020\u8fc7\u7a0b \u6784\u9020\u8fc7\u7a0b\u662f\u4e3a\u4e86\u4f7f\u7528\u67d0\u4e2a\u7c7b\u3001\u7ed3\u6784\u4f53\u6216\u679a\u4e3e\u7c7b\u578b\u7684\u5b9e\u4f8b\u800c\u8fdb\u884c\u7684\u51c6\u5907\u8fc7\u7a0b\u3002\u8fd9&hellip;Read More","og_url":"https:\/\/www.puzi7.net\/?p=542","og_site_name":"\u8c31\u5b50\u68cb - Puzi7","article_published_time":"2018-02-23T15:39:07+00:00","author":"\u77f3\u8863","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u77f3\u8863","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.puzi7.net\/?p=542#article","isPartOf":{"@id":"https:\/\/www.puzi7.net\/?p=542"},"author":{"name":"\u77f3\u8863","@id":"https:\/\/www.puzi7.net\/#\/schema\/person\/87dd4941c8ec260c1350b7f41980a190"},"headline":"Swift \u6784\u9020\u8fc7\u7a0b","datePublished":"2018-02-23T15:39:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.puzi7.net\/?p=542"},"wordCount":61,"commentCount":0,"keywords":["iOS","Swift"],"articleSection":["Mobile","Swift"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.puzi7.net\/?p=542#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.puzi7.net\/?p=542","url":"https:\/\/www.puzi7.net\/?p=542","name":"Swift \u6784\u9020\u8fc7\u7a0b - \u8c31\u5b50\u68cb - Puzi7","isPartOf":{"@id":"https:\/\/www.puzi7.net\/#website"},"datePublished":"2018-02-23T15:39:07+00:00","author":{"@id":"https:\/\/www.puzi7.net\/#\/schema\/person\/87dd4941c8ec260c1350b7f41980a190"},"breadcrumb":{"@id":"https:\/\/www.puzi7.net\/?p=542#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.puzi7.net\/?p=542"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.puzi7.net\/?p=542#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.puzi7.net\/"},{"@type":"ListItem","position":2,"name":"\u6280\u672f","item":"https:\/\/www.puzi7.net\/?cat=9"},{"@type":"ListItem","position":3,"name":"Mobile","item":"https:\/\/www.puzi7.net\/?cat=26"},{"@type":"ListItem","position":4,"name":"Swift","item":"https:\/\/www.puzi7.net\/?cat=28"},{"@type":"ListItem","position":5,"name":"Swift \u6784\u9020\u8fc7\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.puzi7.net\/#website","url":"https:\/\/www.puzi7.net\/","name":"\u8c31\u5b50\u68cb - Puzi7","description":"\u5206\u4eab\uff0c\u6210\u957f","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.puzi7.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.puzi7.net\/#\/schema\/person\/87dd4941c8ec260c1350b7f41980a190","name":"\u77f3\u8863","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c52c3a64b447af78e58cfa1c73ddd53952049afcf934cd702d71eee91f9907bd?s=96&d=mm&r=g","caption":"\u77f3\u8863"},"sameAs":["https:\/\/www.puzi7.net"],"url":"https:\/\/www.puzi7.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=542"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/542\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}