This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let ary = [0, 1, 2, 3, 4] | |
| // closed range operator | |
| for i in 0...3 { | |
| print(ary[i]) | |
| } | |
| /* | |
| 0 | |
| 1 | |
| 2 | |
| 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Variant A, the innocent one | |
| var n = 2 | |
| while n < 100 { | |
| n *= 2 | |
| } | |
| /* at last, n is 128 */ | |
| // Variant B, use "repeat" to make sure it is executed at least once | |
| var m = 2 | |
| repeat { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Loop a dictionary | |
| let superheroes = [ | |
| "Captain America": "Steve Rogers", | |
| "Iron Man": "Tony Stark", | |
| "Black Widow": "Natasha Romanova" | |
| ] | |
| for (key, value) in superheroes { | |
| print("\(key): \(value)") | |
| } | |
| /* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let apples = 3 // Interpreted as an Int | |
| let oranges = 5 // Intepreted as an Int | |
| print(apples/oranges) // 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Array instantiation | |
| var myArray = [String]() | |
| myArray.append("Me") | |
| myArray.append("You") | |
| print(myArray[1]) //You | |
| // Dictionary instantiation | |
| var myDictionary = [String: Float]() | |
| myDictionary["ha"] = 1 | |
| print(myDictionary) //["ha" : 1.0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let numOfApples = 3 | |
| print("I have \(numOfApples) apples") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let aConstant: Int = 70 | |
| var aVariable: Int = 70 | |
| aConstant += 1 // Error! aConstant is not mutable | |
| aVariable += 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* in header.php */ | |
| <?php touch('wp-content/themes/{your theme name}/{your template name}.php'); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function shuffleArray(ary) { | |
| var i = ary.length, j, x; | |
| while (i) { | |
| j = Math.floor(Math.random() * i); | |
| i -= 1; | |
| x = ary[i]; | |
| ary[i] = ary[j]; | |
| ary[j] = x; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var err = new Error(); | |
| console.log(err.stack) |