﻿{"id":336,"date":"2015-08-21T16:20:05","date_gmt":"2015-08-21T08:20:05","guid":{"rendered":"http:\/\/blog.sway.com.cn\/?p=336"},"modified":"2015-08-21T16:20:17","modified_gmt":"2015-08-21T08:20:17","slug":"swift%e7%b1%bb%e5%9e%8b%e4%b9%8b%e9%97%b4%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"http:\/\/blog.sway.com.cn\/?p=336","title":{"rendered":"Swift\u7c7b\u578b\u4e4b\u95f4\u8f6c\u6362"},"content":{"rendered":"<p><strong>Int\u8f6c\u6362Float\u6216Double\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php\">let intVar : Int = 3\r\nlet doubleVar : Double = Double(intVar)<\/pre>\n<p><strong>Int\u8f6c\u6362\u4e3aString\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php\">let intVar : Int = 3\r\nlet strVar : String = String(intVar)<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>String\u8f6c\u6362\u4e3aInt\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php\">let strVar : String = \"123\"\r\nlet intVar : Int? = strVar.toInt()<\/pre>\n<p><strong>Double\u8f6c\u6362\u4e3aString\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php\">let doubleVar : Double = 3.14\r\nlet strVar : String = String(doubleVar)<\/pre>\n<p><strong>Double\u4fdd\u7559\u4e24\u4f4d\u5c0f\u6570\uff0c\u9700\u8981\u5bf9Double\u8fdb\u884c\u6269\u5c55\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php\">extension Double {\r\n    func format(f: String) -&gt; String {\r\n        return NSString(format: \"%\\(f)f\", self)\r\n    }\r\n}\r\nlet myDouble = 1.234567\r\nprintln(myDouble.format(\".2\")<\/pre>\n<p><strong>String\u8f6c\u6362Double\uff1a<\/strong><\/p>\n<pre class=\"prettyprint lang-php \">let strVar : String = \"3.14\"\r\nvar string = NSString(string: strVar)\r\nstring.doubleValue<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Int\u8f6c\u6362Float\u6216Double\uff1a let intVar : Int = 3 let doubleVar : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[],"class_list":["post-336","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=336"}],"version-history":[{"count":1,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions"}],"predecessor-version":[{"id":337,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/336\/revisions\/337"}],"wp:attachment":[{"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=336"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.sway.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}