{"id":510,"date":"2018-02-23T23:38:53","date_gmt":"2018-02-23T15:38:53","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-%e5%8f%98%e9%87%8f\/"},"modified":"2018-02-23T23:38:53","modified_gmt":"2018-02-23T15:38:53","slug":"swift-%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=510","title":{"rendered":"Swift \u53d8\u91cf"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift \u53d8\u91cf<\/h1>\n<p>\n\u53d8\u91cf\u662f\u4e00\u79cd\u4f7f\u7528\u65b9\u4fbf\u7684\u5360\u4f4d\u7b26\uff0c\u7528\u4e8e\u5f15\u7528\u8ba1\u7b97\u673a\u5185\u5b58\u5730\u5740\u3002\n<\/p>\n<p>\nSwift \u6bcf\u4e2a\u53d8\u91cf\u90fd\u6307\u5b9a\u4e86\u7279\u5b9a\u7684\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u51b3\u5b9a\u4e86\u53d8\u91cf\u5360\u7528\u5185\u5b58\u7684\u5927\u5c0f\uff0c\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u4e5f\u51b3\u5b9a\u53ef\u5b58\u50a8\u503c\u7684\u8303\u56f4\u3002\n<\/p>\n<p>\u4e0a\u4e00\u7ae0\u8282\u6211\u4eec\u5df2\u7ecf\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86<a href=\"http:\/\/www.runoob.com\/swift\/swift-data-types.html\" target=\"_blank\">\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b<\/a>\uff0c\u5305\u62ec\u6574\u5f62Int\u3001\u6d6e\u70b9\u6570Double\u548cFloat\u3001\u5e03\u5c14\u7c7b\u578bBool\u4ee5\u53ca\u5b57\u7b26\u4e32\u7c7b\u578bString\u3002\u6b64\u5916\uff0cSwift\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u66f4\u5f3a\u5927\u6570\u636e\u7c7b\u578b\uff0c Optional, Array, Dictionary, Struct, \u548c Class \u7b49\u3002<\/p>\n<p>\n\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u5982\u4f55\u5728 Swift \u7a0b\u5e8f\u4e2d\u58f0\u660e\u548c\u4f7f\u7528\u53d8\u91cf\u3002<\/p>\n<hr>\n<h2>\u53d8\u91cf\u58f0\u660e<\/h2>\n<p>\u53d8\u91cf\u58f0\u660e\u610f\u601d\u662f\u544a\u8bc9\u7f16\u8bd1\u5668\u5728\u5185\u5b58\u4e2d\u7684\u54ea\u4e2a\u4f4d\u7f6e\u4e0a\u4e3a\u53d8\u91cf\u521b\u5efa\u591a\u5927\u7684\u5b58\u50a8\u7a7a\u95f4\u3002<\/p>\n<p>\u5728\u4f7f\u7528\u53d8\u91cf\u524d\uff0c\u4f60\u9700\u8981\u4f7f\u7528 <b>var<\/b> \u5173\u952e\u5b57\u58f0\u660e\u5b83\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>\nvar variableName = &lt;initial value&gt;\n<\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a Swift \u7a0b\u5e8f\u4e2d\u53d8\u91cf\u58f0\u660e\u7684\u7b80\u5355\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nimport Cocoa\n\nvar varA = 42\nprint(varA)\n\nvar varB:Float\n\nvarB = 3.14159\nprint(varB)\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n42\n3.14159<\/pre>\n<hr>\n<h2>\u53d8\u91cf\u547d\u540d<\/h2>\n<p>\n\u53d8\u91cf\u540d\u53ef\u4ee5\u7531\u5b57\u6bcd\uff0c\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u7ec4\u6210\u3002<\/p>\n<p>\n\u53d8\u91cf\u540d\u9700\u8981\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u59cb\u3002<\/p>\n<p>Swift \u662f\u4e00\u4e2a\u533a\u5206\u5927\u5c0f\u5199\u7684\u8bed\u8a00\uff0c\u6240\u4ee5\u5b57\u6bcd\u5927\u5199\u4e0e\u5c0f\u5199\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n<p>\u53d8\u91cf\u540d\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7b80\u5355\u7684 Unicode \u5b57\u7b26\uff0c\u5982\u4e0b\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nimport Cocoa\n\nvar _var = \"Hello, Swift!\"\nprint(_var)\n\nvar \u4f60\u597d = \"\u4f60\u597d\u4e16\u754c\"\nvar \u83dc\u9e1f\u6559\u7a0b = \"www.runoob.com\"\nprint(\u4f60\u597d)\nprint(\u83dc\u9e1f\u6559\u7a0b)\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nHello, Swift!\n\u4f60\u597d\u4e16\u754c\nwww.runoob.com\n<\/pre>\n<hr>\n<h2>\u53d8\u91cf\u8f93\u51fa<\/h2>\n<p>\u53d8\u91cf\u548c\u5e38\u91cf\u53ef\u4ee5\u4f7f\u7528 <b>print<\/b>\uff08swift 2 \u5c06 print \u66ff\u6362\u4e86 println\uff09 \u51fd\u6570\u6765\u8f93\u51fa\u3002<\/p>\n<p>\u5728\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u4f7f\u7528\u62ec\u53f7\u4e0e\u53cd\u659c\u7ebf\u6765\u63d2\u5165\u53d8\u91cf\uff0c\u5982\u4e0b\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nimport Cocoa\n\nvar name = \"\u83dc\u9e1f\u6559\u7a0b\"\nvar site = \"http:\/\/www.runoob.com\"\n\nprint(\"\\(name)\u7684\u5b98\u7f51\u5730\u5740\u4e3a\uff1a\\(site)\")\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\n\u83dc\u9e1f\u6559\u7a0b\u7684\u5b98\u7f51\u5730\u5740\u4e3a\uff1ahttp:\/\/www.runoob.com\n<\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift \u53d8\u91cf \u53d8\u91cf\u662f\u4e00\u79cd\u4f7f\u7528\u65b9\u4fbf\u7684\u5360\u4f4d\u7b26\uff0c\u7528\u4e8e\u5f15\u7528\u8ba1\u7b97\u673a\u5185\u5b58\u5730\u5740\u3002 Swift \u6bcf\u4e2a\u53d8&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=510\">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-510","post","type-post","status-publish","format-standard","hentry","category-mobile","category-swift","tag-ios","tag-swift","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/510","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=510"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/510\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}