Lists
This page is under construction. Please come back later.
#!/usr/bin/env swift; import Foundation import Utils // Begin Main let NUM_SQUARES:Int = 5 var squares:[Int] = [] // Put the squares into the list for i:Int in 0..<NUM_SQUARES { squares.append(i * i) } // Print out the squares from the list for i:Int in 0..<squares.count { print(Utils.format("{0:d}^2 = {1:d}", i, squares[i])) } print(Utils.listToString(squares)) exit(EXIT_SUCCESS)
Output
$ swiftc Lists1.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation import Utils // Begin Main var squares:[Int] = [0, 1, 4, 9, 16, 25] // Print out the squares from the list for i:Int in 0..<squares.count { print(Utils.format("{0:d}^2 = {1:d}", i, squares[i])) } exit(EXIT_SUCCESS)
Output
$ swiftc Lists2.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation // Begin Main var names:[String] = ["Fred", "Wilma", "Barney", "Betty"] for name in names { print("Hello, " + name + "!") } names = ["Harry", "Ron", "Hermione"] for name in names { print("Hello, " + name + "!") } exit(EXIT_SUCCESS)
Output
$ swiftc Lists3.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation import Utils // Begin Main // Print out the command line arguments for i:Int in 1...(CommandLine.arguments.count - 1) { print(String(i) + ":" + CommandLine.arguments[i]) } exit(EXIT_SUCCESS)
Output
$ swiftc Lists4.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc Lists4.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#!/usr/bin/env swift; import Foundation import Utils // Begin Main var names:[String] = ["Fred", "Wilma", "Barney", "Betty"] // Print out the name based on command line argument 1-4 for i:Int in 1...(CommandLine.arguments.count - 1) { let x:Int = Int(CommandLine.arguments[i]) ?? 0 print(String(i) + ":" + names[x - 1]) } exit(EXIT_SUCCESS)
Output
$ swiftc Lists5.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc Lists5.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$ swiftc Lists5.swift -I . -L . -lUtils
error: link command failed with exit code 1 (use -v to see invocation)
ld: library not found for -lUtils
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Questions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- Array Last Element
- Central Limit Theorem
- Chromatic Scale Frequencies
- Income Tax (Revisited)
- Morse Code
- Renard Numbers (Preferred Numbers)
- Sample Mean and Standard Deviation
- Sieve of Eratosthenes
References
- [[Swift Community]]
- [[Swift Language Guide]]
- [[Swift Language Reference]]
- [[Swift Programming Language]], Apple Inc.
- [[Swift Doc]]
- [[We Heart Swift]]
- [[Swift Cookbook]]
- [[Swift Playground]]
- [[Swift at TutorialsPoint]]
- [[Hacking with Swift]]