main
ostrichb 3 years ago
commit 02f98de322
No known key found for this signature in database
GPG Key ID: 1B83C199FDCEEC08

26
.gitignore vendored

@ -0,0 +1,26 @@
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

@ -0,0 +1,26 @@
import Foundation
// Write your code here...
func varProcessor(_ n: Any) {
let nInt = n as? Int ?? 0 // nnIntn
let nString = n as? String ?? "" // nnStringn
switch n {
case is Int:
// n
// Write your code here...
case is String:
// n
// Write your code here...
default:
print("An error occurred.")
}
}
//
let test: [Any] = [0, 2, 0.2, "Hello"]
for item in test {
varProcessor(item)
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task1_practice.playground#CharacterRangeLen=532&amp;CharacterRangeLoc=0&amp;EndingColumnNumber=0&amp;EndingLineNumber=26&amp;StartingColumnNumber=0&amp;StartingLineNumber=0&amp;Timestamp=689874495.77337"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>

@ -0,0 +1,22 @@
import Foundation
func varProcessor(_ n: Any, /* Write your code here */) {
let nInt = n as? Int ?? 0 // nnIntn
let nString = n as? String ?? "" // nnStringn
switch n{
case is Int:
// n
// Write your code here...
case is String:
// n
// Write your code here...
default:
print("An error occurred.")
}
}
let test: [Any] = [0, 2, 0.2, "Hello"]
for item in test {
varProcessor(item, /* Write your code here */)
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task2_pracitce.playground#CharacterRangeLen=528&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=22&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689908036.025995"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Task2_pracitce (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

@ -0,0 +1,14 @@
import Foundation
struct Entity {
// Write your code here
}
// ID 13
// let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return false
// }
// return true

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task3_practice.playground#CharacterRangeLen=414&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=14&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689911183.10065"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task3_practice.playground#CharacterRangeLen=414&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=14&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689911183.10071"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task3_practice.playground#CharacterRangeLen=414&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=14&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689911183.100747"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task3_practice.playground#CharacterRangeLen=414&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=14&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689911183.100782"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task3_practice.playground#CharacterRangeLen=414&amp;CharacterRangeLoc=17&amp;EndingColumnNumber=0&amp;EndingLineNumber=14&amp;StartingColumnNumber=17&amp;StartingLineNumber=0&amp;Timestamp=689911183.1008151"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>

@ -0,0 +1,68 @@
import Foundation
class Entity {
// Write your code here
func verify() -> Bool {
// Write your code here
}
}
class Student: Entity {
override func verify() -> Bool {
// Write your code here
}
}
class Cat: Entity {
override func verify() -> Bool {
// Write your code here
}
}
// ID 1320xx51-3
// let reFormula = try! NSRegularExpression(pattern: "^20\\d{2}[1-3]\\d{8}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return false
// }
// return true
// ID 13
// let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return false
// }
// return true
// ID 130000
// let reFormula = try! NSRegularExpression(pattern: "^0000\\d{9}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return false
// }
// return true
//
var fly = Entity()
fly.ID = "0000000099003"
fly.name = "蒼蠅"
fly.verify()
var siuming = Student()
siuming.ID = "2021502233076"
siuming.name = "小明"
siuming.verify()
var siuhung = Student()
siuhung.ID = "2022302191000"
siuhung.name = "小紅"
siuhung.verify()
var policecat = Cat()
policecat.ID = "0000999988222"
policecat.name = "警長"
policecat.verify()

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task4_practice.playground#CharacterRangeLen=740&amp;CharacterRangeLoc=1090&amp;EndingColumnNumber=0&amp;EndingLineNumber=68&amp;StartingColumnNumber=0&amp;StartingLineNumber=38&amp;Timestamp=689912106.149693"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task4_practice.playground#CharacterRangeLen=740&amp;CharacterRangeLoc=1090&amp;EndingColumnNumber=0&amp;EndingLineNumber=68&amp;StartingColumnNumber=0&amp;StartingLineNumber=38&amp;Timestamp=689912106.149847"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task4_practice.playground#CharacterRangeLen=740&amp;CharacterRangeLoc=1090&amp;EndingColumnNumber=0&amp;EndingLineNumber=68&amp;StartingColumnNumber=0&amp;StartingLineNumber=38&amp;Timestamp=689912106.14995"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task4_practice.playground#CharacterRangeLen=740&amp;CharacterRangeLoc=1090&amp;EndingColumnNumber=0&amp;EndingLineNumber=68&amp;StartingColumnNumber=0&amp;StartingLineNumber=38&amp;Timestamp=689912106.150052"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task4_practice.playground#CharacterRangeLen=740&amp;CharacterRangeLoc=1090&amp;EndingColumnNumber=0&amp;EndingLineNumber=68&amp;StartingColumnNumber=0&amp;StartingLineNumber=38&amp;Timestamp=689912106.150148"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Task4_practice (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

@ -0,0 +1,51 @@
import Foundation
// task 4 task 4
// ID 1320xx51-3
// let reFormula = try! NSRegularExpression(pattern: "^20\\d{2}[1-3]\\d{8}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return nil
// }
// ID 13
// let reFormula = try! NSRegularExpression(pattern: "^\\d{13}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return nil
// }
// ID 130000
// let reFormula = try! NSRegularExpression(pattern: "^0000\\d{9}$", options: [NSRegularExpression.Options.anchorsMatchLines])
// let matchRange = NSRange(ID.startIndex..<ID.endIndex, in: ID)
// let matchList = reFormula.matches(in: ID, range: matchRange)
// if matchList.count != 1 {
// return nil
// }
//
var siuziu = Student(id: "2022202121000", name: "小趙")
var siuchow = Student(id: "2000503205613", name: "小周")
var studentList = [siuziu, siuchow]
for item in studentList {
guard item != nil else {
print("Invalid students")
continue
}
do {
var count = 0
while true{
count += 1
try item!.work()
print("Siu Ziu has worked for \(String(count)) \(count <= 1 ? "hour" : "hours").")
}
}
catch InsufficientEnergy.crazyThursdayVMe50 {
print("I'm hungry, please v me 50!")
}
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' buildActiveScheme='true' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:">
</FileRef>
</Workspace>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=1676&amp;CharacterRangeLoc=57&amp;EndingColumnNumber=0&amp;EndingLineNumber=51&amp;StartingColumnNumber=0&amp;StartingLineNumber=3&amp;Timestamp=689915859.917581"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=1676&amp;CharacterRangeLoc=57&amp;EndingColumnNumber=0&amp;EndingLineNumber=51&amp;StartingColumnNumber=0&amp;StartingLineNumber=3&amp;Timestamp=689915859.917655"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=1676&amp;CharacterRangeLoc=57&amp;EndingColumnNumber=0&amp;EndingLineNumber=51&amp;StartingColumnNumber=0&amp;StartingLineNumber=3&amp;Timestamp=689915859.9177051"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=1676&amp;CharacterRangeLoc=57&amp;EndingColumnNumber=0&amp;EndingLineNumber=51&amp;StartingColumnNumber=0&amp;StartingLineNumber=3&amp;Timestamp=689915859.91775"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=1676&amp;CharacterRangeLoc=57&amp;EndingColumnNumber=0&amp;EndingLineNumber=51&amp;StartingColumnNumber=0&amp;StartingLineNumber=3&amp;Timestamp=689915859.9177901"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ostrichb/Downloads/Task5_practice.playground#CharacterRangeLen=6&amp;CharacterRangeLoc=1162&amp;EndingColumnNumber=11&amp;EndingLineNumber=29&amp;StartingColumnNumber=5&amp;StartingLineNumber=29&amp;Timestamp=689915859.917832"
selectedRepresentationIndex = "0">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>
Loading…
Cancel
Save