{"id":555,"date":"2023-02-25T18:59:47","date_gmt":"2023-02-25T10:59:47","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=555"},"modified":"2023-04-29T20:37:03","modified_gmt":"2023-04-29T12:37:03","slug":"swift-basic-data-types-constant-and-variable-declarations","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-basic-data-types-constant-and-variable-declarations\/","title":{"rendered":"Swift &#8211; \u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u5e38\u91cf\u53ca\u53d8\u91cf\u58f0\u660e"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<h3>\u53d8\u91cf\uff1a\u4f7f\u7528var\u58f0\u660e<\/h3>\n<pre><code class=\"language-swift\">var str:String = &quot;appblog.cn&quot;<\/code><\/pre>\n<p><!-- more --><\/p>\n<h3>\u5e38\u91cf\uff1a\u4f7f\u7528let\u58f0\u660e<\/h3>\n<pre><code class=\"language-swift\">let count:Int = 32<\/code><\/pre>\n<h3>\u6574\u578b<\/h3>\n<p>\u6709\u7b26\u53f7\u6574\u5f62\uff1aInt\uff0cInt8\uff0cInt16\uff0cInt32\uff0cInt64<br \/>\n\u65e0\u7b26\u53f7\u6574\u5f62\uff1aUInt\uff0cUInt8\uff0cUInt16\uff0cUInt32\uff0cUInt64<\/p>\n<h3>\u6d6e\u70b9\u578b<\/h3>\n<p>Float\uff1a32\u4f4d\u6d6e\u70b9\u6570\u7c7b\u578b<br \/>\nDouble\uff1a64\u4f4d\u6d6e\u70b9\u6570\u7c7b\u578b<\/p>\n<h3>\u5e03\u5c14\u578b\uff1aBool<\/h3>\n<h3>\u5b57\u7b26\u4e32\uff1aString<\/h3>\n<p>\uff081\uff09\u5224\u65ad\u662f\u5426\u4e3a\u7a7a\uff1aisEmpty<\/p>\n<pre><code class=\"language-swift\">var str:String = &quot;&quot;\nif str.isEmpty{\n    print(&quot;\u7a7a\u5b57\u7b26\u4e32&quot;)\n}<\/code><\/pre>\n<p>\uff082\uff09\u83b7\u53d6\u5b57\u7b26\u6570\u91cf\uff1astring.characters.count<\/p>\n<pre><code class=\"language-swift\">let str = &quot;appblog.cn&quot;\nprint(&quot;\\(str.count)\u4e2a\u5b57\u7b26&quot;)<\/code><\/pre>\n<p>\uff083\uff09\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u6709\u7279\u5b9a\u524d\u7f00\/\u540e\u7f00\uff1ahasPrefix\/hasSuffix<\/p>\n<pre><code class=\"language-swift\">var str = &quot;appblog.cn&quot;\nif str.hasSuffix(&quot;.com&quot;){\n}<\/code><\/pre>\n<p>\uff084\uff09\u8fd8\u53ef\u4ee5\u7528\u201c()\u201d\u5728\u5b57\u7b26\u4e32\u91cc\u5305\u88f9\u53d8\u91cf\uff0c\u5e38\u91cf<\/p>\n<pre><code class=\"language-swift\">let name = &quot;appblog.cn&quot;\nlet msg = &quot;\u6b22\u8fce\u6765\u5230 \\(name)&quot;<\/code><\/pre>\n<p>\uff085\uff09\u5927\u5c0f\u5199\u8f6c\u6362<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u7684uppercased()\u65b9\u6cd5\u3001lowercased()\u65b9\u6cd5\u3001capitalized\u5c5e\u6027\u6765\u8bbf\u95ee\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5927\u5199\/\u5c0f\u5199\/\u9996\u5b57\u6bcd\u5927\u5199<\/p>\n<pre><code class=\"language-swift\">let str = &quot;Welecome to appblog.cn&quot;\n\nvar uppercase = str.uppercased()  \/\/WELECOME TO APPBLOG.CN\nvar lowercase = str.lowercased()  \/\/welecome to appblog.cn\nvar capitalized = str.capitalized  \/\/Welecome To Appblog.Cn<\/code><\/pre>\n<h3>\u5b57\u7b26\uff1aCharacter<\/h3>\n<pre><code class=\"language-swift\">var doller:Character = &quot;$&quot;<\/code><\/pre>\n<h3>\u5143\u7ec4<\/h3>\n<pre><code class=\"language-swift\">let person = (name:&quot;Joe.Ye&quot;, age:25)\nprint(&quot;\\(person.name)&quot;)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u53d8\u91cf\uff1a\u4f7f\u7528var\u58f0\u660e var str:String = &quot;appblo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171],"tags":[],"class_list":["post-555","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/555\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}