{"rsdb":{"rid":"345949","subhead":"","postdate":"0","aid":"246442","fid":"89","uid":"1","topic":"1","content":"
\n

\u8fd0\u7b97\u7b26\u662f\u7528\u6765\u68c0\u67e5\uff0c\u66f4\u6539\u6216\u7ec4\u5408\u503c\u7684\u7279\u6b8a\u7b26\u53f7\u6216\u77ed\u8bed\u3002Swift\u63d0\u4f9b\u7684\u5f88\u591a\u5e38\u89c4\u7684\u8fd0\u7b97\u7b26\uff0c\u5982+\u3001-\u3001*\u3001\/\u3001%\u3001=\u3001==\u7b49\uff0c\u4ee5\u53ca\u903b\u8f91\u8fd0\u7b97\u7684&&\u3001||\u7b49\u7b49\uff0c\u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u91cd\u590d\u4ecb\u7ecd\uff0c\u6211\u4eec\u5728\u8fd9\u91cc\u53ea\u9700\u8981\u4e86\u89e3\u4e00\u4e9b\u4e0d\u592a\u4e00\u6837\u7684\u8fd0\u7b97\u7b26\u5c31\u53ef\u4ee5\u4e86\u3002\u5982Swift\u5f15\u5165\u7684\u65b0\u8fd0\u7b97\u7b26\uff0c\u8303\u56f4\u64cd\u4f5c\u7b26\u53f7\uff0c\u5305\u62ec..<\u548c...\u4e24\u4e2a\uff0c\u8be5\u968f\u7b14\u4ecb\u7ecdSwift\u5e38\u89c4\u7684\u8fd0\u7b97\u7b26\u4e2d\uff0c\u4ee5\u53ca\u548c\u5176\u4ed6\u8bed\u8a00\u6709\u6240\u5dee\u5f02\u7684\u90e8\u5206\u3002<\/p> \n

 <\/p> \n

\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h3> \n
\n
let b = 10\r\nvar a = 5\r\na = b\r\n\/\/ a is now equal to 10\r\n<\/pre> \n <\/div> \n 

 \u8d4b\u503c\u8bed\u53e5\uff0c\u5904\u7406\u548c\u5176\u4ed6\u8bed\u8a00\u4e00\u6837\u3002<\/p> \n

 <\/p> \n

\n
let (x, y) = (1, 2)\r\n\/\/ x is equal to 1, and y is equal to 2\r\n<\/pre> \n <\/div> \n 

 \u8fd9\u79cd\u4ee3\u7801\u662f\u7c7b\u4f3cECMAScript 6\u7684\u811a\u672c\u5199\u6cd5\uff0c\u901a\u8fc7\u628a\u53f3\u8fb9\u5143\u7956\u5bf9\u8c61\u89e3\u6784\u8d4b\u503c\u7ed9\u5de6\u8fb9\u5bf9\u5e94\u7684\u53c2\u6570\u3002<\/p> \n

 <\/p> \n

\u6570\u5b66\u8fd0\u7b97\u7b26<\/h3> \n
\n
1 + 2       \/\/ equals 3\r\n5 - 3       \/\/ equals 2\r\n2 * 3       \/\/ equals 6\r\n10.0 \/ 2.5  \/\/ equals 4.0\r\n<\/pre> \n <\/div> \n 

 \u8fd9\u4e9b\u90fd\u662f\u548c\u5176\u4ed6\u8bed\u8a00\u6ca1\u6709\u4ec0\u4e48\u4e0d\u540c\uff0c\u5faa\u4f8b\u5217\u51fa\u53c2\u8003\u4e0b<\/p> \n

\u5bf9\u4e8e\u5b57\u7b26\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528+\u7b26\u53f7\u8fdb\u884c\u8fde\u63a5\u65b0\u7684\u5b57\u7b26\u4e32<\/p> \n

\n
"hello, " + "world"  \/\/ equals "hello, world"\r\n<\/pre> \n <\/div> \n 

 <\/p> \n

\u4e00\u5143\u64cd\u4f5c\u7b26\u4e2d\u7684-\u3001+\u8fd0\u7b97\uff0c\u548c\u7b97\u672f\u91cc\u9762\u7684\u8d1f\u8d1f\u5f97\u6b63\uff0c\u6b63\u8d1f\u5f97\u8d1f\u7684\u610f\u601d\u4e00\u6837\u4e86\u3002<\/p> \n

\n
let three = 3\r\nlet minusThree = -three       \/\/ minusThree equals -3\r\nlet plusThree = -minusThree   \/\/ plusThree equals 3, or "minus minus three"\r\n<\/pre> \n <\/div> \n 

 <\/p> \n

\n
let minusSix = -6\r\nlet alsoMinusSix = +minusSix  \/\/ alsoMinusSix equals -6\r\n<\/pre> \n <\/div> \n 

 <\/p> \n

\u7ec4\u5408\u8fd0\u7b97\u7b26\u63d0\u4f9b+= \u3001-=\u7684\u8fd0\u7b97\u7b26\u64cd\u4f5c<\/p> \n

\n
var a = 1\r\na += 2\r\n\/\/ a is now equal to 3\r\n<\/pre> \n <\/div> \n 

 <\/p> \n

\u5bf9\u6bd4\u8fd0\u7b97\u7b26\u548c\u5176\u4ed6\u8bed\u8a00\u5dee\u4e0d\u591a<\/p> \n

    \n
  • \u7b49\u4e8e (a == b<\/code>)<\/p> <\/li> \n

  • \u4e0d\u7b49\u4e8e (a != b<\/code>)<\/p> <\/li> \n

  • \u5927\u4e8e (a > b<\/code>)<\/p> <\/li> \n

  • \u5c0f\u4e8e (a < b<\/code>)<\/p> <\/li> \n

  • \u5927\u4e8e\u7b49\u4e8e (a >= b<\/code>)<\/p> <\/li> \n

  • \u5c0f\u4e8e\u7b49\u4e8e (a <= b<\/code>)<\/p> <\/li> \n <\/ul> \n

    \u53e6\u5916\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0cSwift\u63d0\u4f9b\u4e86\u5bf9\u6bd4\u5f15\u7528\u7684\u4e24\u4e2a\u64cd\u4f5c\u7b26\u53f7\uff0c===<\/code> \u548c !==\uff0c\u7528\u6765\u68c0\u67e5\u4e24\u4e2a\u5f15\u7528\u662f\u5426\u5b8c\u5168\u76f8\u7b49\uff1b\u6216\u8005\u4e0d\u76f8\u7b49\u7684\u3002\u800c==\u53ea\u662f\u7528\u6765\u5bf9\u6bd4\u4e24\u4e2a\u5bf9\u8c61\u7684\u503c\u662f\u5426\u4e00\u81f4\u3002<\/code><\/p> \n

    \n
    1 == 1   \/\/ true because 1 is equal to 1\r\n2 != 1   \/\/ true because 2 is not equal to 1\r\n2 > 1    \/\/ true because 2 is greater than 1\r\n1 < 2    \/\/ true because 1 is less than 2\r\n1 >= 1   \/\/ true because 1 is greater than or equal to 1\r\n2 <= 1   \/\/ false because 2 is not less than or equal to 1\r\n<\/pre> \n <\/div> \n 

     \u5bf9\u6bd4\u8fd0\u7b97\u7b26\u4e5f\u7ecf\u5e38\u7528\u6765If\u6761\u4ef6\u8bed\u53e5\u91cc\u9762<\/p> \n

    \n
    let name = "world"\r\nif name == "world" {\r\n    print("hello, world")\r\n} else {\r\n    print("I'm sorry \\(name), but I don't recognize you")\r\n}\r\n\/\/ Prints "hello, world", because name is indeed equal to "world".\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \u4e09\u5143\u8fd0\u7b97\u7b26<\/h3> \n

    \u4e09\u5143\u8fd0\u7b97\u7b26 \uff1f \uff1a\u548cC#\u91cc\u9762\u8868\u73b0\u662f\u4e00\u6837\u7684<\/p> \n

    \n
    question ? answer1 : answer2\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \n
    let contentHeight = 40\r\nlet hasHeader = true\r\nlet rowHeight = contentHeight + (hasHeader ? 50 : 20)\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \u7a7a\u503c\u8f6c\u6362\u64cd\u4f5c\u7b26<\/h3> \n

    \u7a7a\u503c\u8f6c\u6362\u7b26\u662f\u5bf9\u53ef\u7a7a\u7c7b\u578b\uff08\u53ef\u9009\u7c7b\u578b\uff09\u7684\u4e00\u4e2a\u503c\u5f97\u8f6c\u6362\u51fa\u6765(a ?? b<\/code>)\u3002<\/p> \n

    \n
    let defaultColorName = "red"\r\nvar userDefinedColorName: String?   \/\/ defaults to nil\r\n \r\nvar colorNameToUse = userDefinedColorName ?? defaultColorName\r\n\/\/ userDefinedColorName is nil, so colorNameToUse is set to the default of "red"\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \n
    userDefinedColorName = "green"\r\ncolorNameToUse = userDefinedColorName ?? defaultColorName\r\n\/\/ userDefinedColorName is not nil, so colorNameToUse is set to "green"\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \u8303\u56f4\u64cd\u4f5c\u7b26<\/h3> \n

    \u95ed\u5408\u8303\u56f4\u8fd0\u7b97\u7b26 ... \u548c\u534a\u95ed\u5408\u8303\u56f4\u8fd0\u7b97\u7b26 ..< \u4e24\u4e2a<\/p> \n

    \n
    for index in 1...5 {\r\n    print("\\(index) times 5 is \\(index * 5)")\r\n}\r\n\/\/ 1 times 5 is 5\r\n\/\/ 2 times 5 is 10\r\n\/\/ 3 times 5 is 15\r\n\/\/ 4 times 5 is 20\r\n\/\/ 5 times 5 is 25\r\n<\/pre> \n <\/div> \n 

     \u534a\u95ed\u5408\u7684\u8303\u56f4\u8fd0\u7b97\u7b26<\/p> \n

    \n
    let names = ["Anna", "Alex", "Brian", "Jack"]\r\nlet count = names.count\r\nfor i in 0..<count {\r\n    print("Person \\(i + 1) is called \\(names[i])")\r\n}\r\n\/\/ Person 1 is called Anna\r\n\/\/ Person 2 is called Alex\r\n\/\/ Person 3 is called Brian\r\n\/\/ Person 4 is called Jack\r\n<\/pre> \n <\/div> \n 

     \u6216\u8005\u5982\u4e0b\u4f7f\u7528<\/p> \n

    \n
    for name in names[..<2] {\r\n    print(name)\r\n}\r\n\/\/ Anna\r\n\/\/ Alex<\/pre> \n <\/div> \n 

     <\/p> \n

    \u4ee5\u53ca\u4e00\u4fa7\u8303\u56f4\u7684\u8fd0\u7b97\u7b26\uff0c\u5305\u62ec\u5de6\u4fa7\u548c\u53f3\u4fa7\u4e24\u4e2a\u90e8\u5206<\/p> \n

    \n
    for name in names[2...] {\r\n    print(name)\r\n}\r\n\/\/ Brian\r\n\/\/ Jack\r\n \r\nfor name in names[...2] {\r\n    print(name)\r\n}\r\n\/\/ Anna\r\n\/\/ Alex\r\n\/\/ Brian\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \n
    let range = ...5\r\nrange.contains(7)   \/\/ false\r\nrange.contains(4)   \/\/ true\r\nrange.contains(-1)  \/\/ true\r\n<\/pre> \n <\/div> \n 

     <\/p> \n

    \u903b\u8f91\u8fd0\u7b97\u7b26<\/h3> \n
    \n
    let a","orderid":"0","title":"\u5feb\u770bSample\u4ee3\u7801\uff0c\u901f\u5b66Swift\u8bed\u8a00\uff083\uff09-\u8fd0\u7b97\u7b26(\u4e00)","smalltitle":"","mid":"0","fname":"Swift","special_id":"0","bak_id":"0","info":"0","hits":"354","pages":"2","comments":"0","posttime":"2019-09-03 02:41:10","list":"1567449670","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u5feb\u770b<\/A> Sample<\/A> \u4ee3\u7801<\/A> \u901f\u5b66<\/A> Swift<\/A> \u8bed\u8a00<\/A> \u8fd0\u7b97<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"120.229.33.54","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u5feb\u770bSample\u4ee3\u7801\uff0c\u901f\u5b66Swift\u8bed\u8a00\uff083\uff09-\u8fd0\u7b97\u7b26","lastview":"1713291093","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}