{"id":513,"date":"2018-02-23T23:38:55","date_gmt":"2018-02-23T15:38:55","guid":{"rendered":"http:\/\/60.205.208.74\/2018\/02\/23\/swift-%e5%ad%97%e9%9d%a2%e9%87%8f\/"},"modified":"2018-02-23T23:38:55","modified_gmt":"2018-02-23T15:38:55","slug":"swift-%e5%ad%97%e9%9d%a2%e9%87%8f","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=513","title":{"rendered":"Swift \u5b57\u9762\u91cf"},"content":{"rendered":"<span itemprop=\"description\"><div class=\"article-body\">\n<div class=\"article-intro\" id=\"content\">\n<h1>Swift \u5b57\u9762\u91cf<\/h1>\n<p>\u6240\u8c13\u5b57\u9762\u91cf\uff0c\u5c31\u662f\u6307\u50cf\u7279\u5b9a\u7684\u6570\u5b57\uff0c\u5b57\u7b26\u4e32\u6216\u8005\u662f\u5e03\u5c14\u503c\u8fd9\u6837\uff0c\u80fd\u591f\u76f4\u63a5\u4e86\u5f53\u5730\u6307\u51fa\u81ea\u5df1\u7684\u7c7b\u578b\u5e76\u4e3a\u53d8\u91cf\u8fdb\u884c\u8d4b\u503c\u7684\u503c\u3002\u6bd4\u5982\u5728\u4e0b\u9762\uff1a<\/p>\n<pre>\nlet aNumber = 3         \/\/\u6574\u578b\u5b57\u9762\u91cf\nlet aString = \"Hello\"   \/\/\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\nlet aBool = true        \/\/\u5e03\u5c14\u503c\u5b57\u9762\u91cf\n<\/pre>\n<hr>\n<h2>\u6574\u578b\u5b57\u9762\u91cf<\/h2>\n<p>\u6574\u578b\u5b57\u9762\u91cf\u53ef\u4ee5\u662f\u4e00\u4e2a\u5341\u8fdb\u5236\uff0c\u4e8c\u8fdb\u5236\uff0c\u516b\u8fdb\u5236\u6216\u5341\u516d\u8fdb\u5236\u5e38\u91cf\u3002<br \/>\n\u4e8c\u8fdb\u5236\u524d\u7f00\u4e3a 0b\uff0c\u516b\u8fdb\u5236\u524d\u7f00\u4e3a 0o\uff0c\u5341\u516d\u8fdb\u5236\u524d\u7f00\u4e3a 0x\uff0c\u5341\u8fdb\u5236\u6ca1\u6709\u524d\u7f00\uff1a\n<\/p>\n<p>\n\u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u6574\u578b\u5b57\u9762\u91cf\u7684\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nlet decimalInteger = 17           \/\/ 17 - \u5341\u8fdb\u5236\u8868\u793a\nlet binaryInteger = 0b10001       \/\/ 17 - \u4e8c\u8fdb\u5236\u8868\u793a\nlet octalInteger = 0o21           \/\/ 17 - \u516b\u8fdb\u5236\u8868\u793a\nlet hexadecimalInteger = 0x11     \/\/ 17 - \u5341\u516d\u8fdb\u5236\u8868\u793a\n<\/pre>\n<hr>\n<h2>\u6d6e\u70b9\u578b\u5b57\u9762\u91cf<\/h2>\n<p>\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u6709\u6574\u6570\u90e8\u5206\uff0c\u5c0f\u6570\u70b9\uff0c\u5c0f\u6570\u90e8\u5206\u53ca\u6307\u6570\u90e8\u5206\u3002<\/p>\n<p>\u9664\u975e\u7279\u522b\u6307\u5b9a\uff0c\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7684\u9ed8\u8ba4\u63a8\u5bfc\u7c7b\u578b\u4e3a Swift \u6807\u51c6\u5e93\u7c7b\u578b\u4e2d\u7684 Double\uff0c\u8868\u793a64\u4f4d\u6d6e\u70b9\u6570\u3002<\/p>\n<p>\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u9ed8\u8ba4\u7528\u5341\u8fdb\u5236\u8868\u793a\uff08\u65e0\u524d\u7f00\uff09\uff0c\u4e5f\u53ef\u4ee5\u7528\u5341\u516d\u8fdb\u5236\u8868\u793a\uff08\u52a0\u524d\u7f00 0x\uff09\u3002<\/p>\n<blockquote>\n<p>\u5341\u8fdb\u5236\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7531\u5341\u8fdb\u5236\u6570\u5b57\u4e32\u540e\u8ddf\u5c0f\u6570\u90e8\u5206\u6216\u6307\u6570\u90e8\u5206\uff08\u6216\u4e24\u8005\u7686\u6709\uff09\u7ec4\u6210\u3002\u5341\u8fdb\u5236\u5c0f\u6570\u90e8\u5206\u7531\u5c0f\u6570\u70b9 . \u540e\u8ddf\u5341\u8fdb\u5236\u6570\u5b57\u4e32\u7ec4\u6210\u3002\u6307\u6570\u90e8\u5206\u7531\u5927\u5199\u6216\u5c0f\u5199\u5b57\u6bcd e \u4e3a\u524d\u7f00\u540e\u8ddf\u5341\u8fdb\u5236\u6570\u5b57\u4e32\u7ec4\u6210\uff0c\u8fd9\u4e32\u6570\u5b57\u8868\u793a e \u4e4b\u524d\u7684\u6570\u91cf\u4e58\u4ee5 10 \u7684\u51e0\u6b21\u65b9\u3002\u4f8b\u5982\uff1a1.25e2 \u8868\u793a 1.25 \u2a09 10^2\uff0c\u4e5f\u5c31\u662f 125.0\uff1b\u540c\u6837\uff0c1.25e\uff0d2 \u8868\u793a 1.25 \u2a09 10^\uff0d2\uff0c\u4e5f\u5c31\u662f 0.0125\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u5341\u516d\u8fdb\u5236\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7531\u524d\u7f00 0x \u540e\u8ddf\u53ef\u9009\u7684\u5341\u516d\u8fdb\u5236\u5c0f\u6570\u90e8\u5206\u4ee5\u53ca\u5341\u516d\u8fdb\u5236\u6307\u6570\u90e8\u5206\u7ec4\u6210\u3002\u5341\u516d\u8fdb\u5236\u5c0f\u6570\u90e8\u5206\u7531\u5c0f\u6570\u70b9\u540e\u8ddf\u5341\u516d\u8fdb\u5236\u6570\u5b57\u4e32\u7ec4\u6210\u3002\u6307\u6570\u90e8\u5206\u7531\u5927\u5199\u6216\u5c0f\u5199\u5b57\u6bcd p \u4e3a\u524d\u7f00\u540e\u8ddf\u5341\u8fdb\u5236\u6570\u5b57\u4e32\u7ec4\u6210\uff0c\u8fd9\u4e32\u6570\u5b57\u8868\u793a p \u4e4b\u524d\u7684\u6570\u91cf\u4e58\u4ee5 2 \u7684\u51e0\u6b21\u65b9\u3002\u4f8b\u5982\uff1a0xFp2 \u8868\u793a 15 \u2a09 2^2\uff0c\u4e5f\u5c31\u662f 60\uff1b\u540c\u6837\uff0c0xFp-2 \u8868\u793a 15 \u2a09 2^-2\uff0c\u4e5f\u5c31\u662f 3.75\u3002<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u8d1f\u7684\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7531\u4e00\u5143\u8fd0\u7b97\u7b26\u51cf\u53f7 &#8211; \u548c\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7ec4\u6210\uff0c\u4f8b\u5982 -42.5\u3002\n<\/p>\n<\/blockquote>\n<p>\n\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u5141\u8bb8\u4f7f\u7528\u4e0b\u5212\u7ebf _ \u6765\u589e\u5f3a\u6570\u5b57\u7684\u53ef\u8bfb\u6027\uff0c\u4e0b\u5212\u7ebf\u4f1a\u88ab\u7cfb\u7edf\u5ffd\u7565\uff0c\u56e0\u6b64\u4e0d\u4f1a\u5f71\u54cd\u5b57\u9762\u91cf\u7684\u503c\u3002\u540c\u6837\u5730\uff0c\u4e5f\u53ef\u4ee5\u5728\u6570\u5b57\u524d\u52a0 0\uff0c\u5e76\u4e0d\u4f1a\u5f71\u54cd\u5b57\u9762\u91cf\u7684\u503c\u3002<\/p>\n<p>\n\u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\u7684\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nlet decimalDouble = 12.1875       \/\/\u5341\u8fdb\u5236\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\nlet exponentDouble = 1.21875e1    \/\/\u5341\u8fdb\u5236\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\nlet hexadecimalDouble = 0xC.3p0   \/\/\u5341\u516d\u8fdb\u5236\u6d6e\u70b9\u578b\u5b57\u9762\u91cf\n<\/pre>\n<hr>\n<h2>\u5b57\u7b26\u4e32\u578b\u5b57\u9762\u91cf<\/h2>\n<p>\u5b57\u7b26\u4e32\u578b\u5b57\u9762\u91cf\u7531\u88ab\u5305\u5728\u53cc\u5f15\u53f7\u4e2d\u7684\u4e00\u4e32\u5b57\u7b26\u7ec4\u6210\uff0c\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>\n\"characters\"<\/pre>\n<p>\u5b57\u7b26\u4e32\u578b\u5b57\u9762\u91cf\u4e2d\u4e0d\u80fd\u5305\u542b\u672a\u8f6c\u4e49\u7684\u53cc\u5f15\u53f7 \uff08&#8221;\uff09\u3001\u672a\u8f6c\u4e49\u7684\u53cd\u659c\u7ebf\uff08\\\uff09\u3001\u56de\u8f66\u7b26\u6216\u6362\u884c\u7b26\u3002<\/p>\n<table class=\"reference\">\n<tbody>\n<tr>\n<th>\u8f6c\u79fb\u5b57\u7b26<\/th>\n<th>\u542b\u4e49<\/th>\n<\/tr>\n<tr>\n<td>\\0<\/td>\n<td>\u7a7a\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\\\<\/td>\n<td> \u53cd\u659c\u7ebf \\<\/td>\n<\/tr>\n<tr>\n<td>\\b<\/td>\n<td>\u9000\u683c(BS) \uff0c\u5c06\u5f53\u524d\u4f4d\u7f6e\u79fb\u5230\u524d\u4e00\u5217<\/td>\n<\/tr>\n<tr>\n<td>\\f<\/td>\n<td>\u6362\u9875(FF)\uff0c\u5c06\u5f53\u524d\u4f4d\u7f6e\u79fb\u5230\u4e0b\u9875\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>\\n<\/td>\n<td>\u6362\u884c\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\r<\/td>\n<td>\u56de\u8f66\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\t<\/td>\n<td>\u6c34\u5e73\u5236\u8868\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\v<\/td>\n<td>\u5782\u76f4\u5236\u8868\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\&#8217;<\/td>\n<td>\u5355\u5f15\u53f7<\/td>\n<\/tr>\n<tr>\n<td>\\&#8221;<\/td>\n<td>\u53cc\u5f15\u53f7<\/td>\n<\/tr>\n<tr>\n<td>\\000<\/td>\n<td>1\u52303\u4f4d\u516b\u8fdb\u5236\u6570\u6240\u4ee3\u8868\u7684\u4efb\u610f\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\\xhh&#8230;<\/td>\n<td>1\u52302\u4f4d\u5341\u516d\u8fdb\u5236\u6240\u4ee3\u8868\u7684\u4efb\u610f\u5b57\u7b26<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n\u4ee5\u4e0b\u4e3a\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u7684\u7b80\u5355\u5b9e\u4f8b\uff1a<\/p>\n<pre>\nimport Cocoa\n\nlet stringL = \"Hello\\tWorld\\n\\n\u83dc\u9e1f\u6559\u7a0b\u5b98\u7f51\uff1a\\'http:\/\/www.runoob.com\\'\"\nprint(stringL)\n<\/pre>\n<p>\u4ee5\u4e0a\u7a0b\u5e8f\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n<pre>\nHello\u00a0\u00a0\u00a0\u00a0World\n\n\u83dc\u9e1f\u6559\u7a0b\u5b98\u7f51\uff1a'http:\/\/www.runoob.com'\n<\/pre>\n<hr>\n<h2>\u5e03\u5c14\u578b\u5b57\u9762\u91cf<\/h2>\n<p>\u5e03\u5c14\u578b\u5b57\u9762\u91cf\u7684\u9ed8\u8ba4\u7c7b\u578b\u662f Bool\u3002<\/p>\n<p>\u5e03\u5c14\u503c\u5b57\u9762\u91cf\u6709\u4e09\u4e2a\u503c\uff0c\u5b83\u4eec\u662f Swift \u7684\u4fdd\u7559\u5173\u952e\u5b57\uff1a<\/p>\n<ul>\n<li>\n<p>true \u8868\u793a\u771f\u3002<\/p>\n<\/li>\n<li>\n<p><b>false<\/b> \u8868\u793a\u5047\u3002<\/p>\n<\/li>\n<li>\n<p><b>nil<\/b> \u8868\u793a\u6ca1\u6709\u503c\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">Swift \u5b57\u9762\u91cf \u6240\u8c13\u5b57\u9762\u91cf\uff0c\u5c31\u662f\u6307\u50cf\u7279\u5b9a\u7684\u6570\u5b57\uff0c\u5b57\u7b26\u4e32\u6216\u8005\u662f\u5e03\u5c14\u503c\u8fd9\u6837\uff0c\u80fd\u591f\u76f4\u63a5\u4e86\u5f53\u5730&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=513\">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-513","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\/513","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=513"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}