Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmsc436PublicF2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Keleher
cmsc436PublicF2021
Commits
b55bf7de
Commit
b55bf7de
authored
3 years ago
by
Peter J. Keleher
Browse files
Options
Downloads
Patches
Plain Diff
auto
parent
5d08a0d5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
demos/03_demo.md
+97
-0
97 additions, 0 deletions
demos/03_demo.md
with
97 additions
and
0 deletions
demos/03_demo.md
0 → 100644
+
97
−
0
View file @
b55bf7de
```
func changeB(a:String, b: inout String) {
b = "\(a)\(b)"
}
var s="this"
changeB(a:"changing ", b:&s)
print(s)
//=====================================================================
func outer() -> (Int) -> Int {
var incr = 0
func inner(_ a:Int) -> Int {
incr += 1
return a+incr
}
return inner
}
let x = outer()
x(33)
//=====================================================================
Array::sorted(by: (T,T)->Bool)
let nums = [7,5,14,12,16]
// Sort with inferred types
let snums = nums.sorted(by:{a,b in a>b})
// Sort with positional parameters
let snums2 = nums.sorted(by:{$0>$1})
// Sort with function name
let snums3 = nums.sorted(by:>)
// Sort with a trailing closure
let snums4 = nums.sorted() {$0>$1}
// Sort with parentheses omitted
let snums5 = nums.sorted {$0>$1}
//=====================================================================
enum Earthsea: CaseIterable {
case AWizardOfEarthsea
case TheTombsOfAtuan
case TheFarthestShore
case Tehanu
}
for book in Earthsea.allCases {
print(book)
}
//=====================================================================
struct Point {
var x: Int = 0
var y: Int = 0
}
let p = Point(x:3, y: 4)
let p2 = Point(x:4, y: 5)
enum Shape {
case circle(center:Point, radius:Double)
case rect(lowerLeft:Point, upperRight:Point)
}
let s = Shape.circle(center:p, radius:1.5)
switch s {
case .circle(let c, let r):
print("It's a circle \(c) \(r)")
case let .rect(ll, ur):
print("Just a rect \(ll) \(ur)")
default:
print("default")
}
let sr = Shape.rect(lowerLeft: p, upperRight: p2)
switch sr {
case .circle(let c, let r):
print("It's a circle \(c) \(r)")
case let .rect(ll, ur):
print("Just a rect \(ll) \(ur)")
default:
print("default")
}
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment