Skip to content

Commit

Permalink
Property observer code
Browse files Browse the repository at this point in the history
  • Loading branch information
codecat15 committed Jan 4, 2020
1 parent e1551dd commit f163b72
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import UIKit

/* Hello there, thanks for downloading the code. I hope the video helped you in understanding property observer. Please do support the channel by subscribing to the video and sharing it with your friends and social media or with anyone who wants to learn swift and clean coding in swift ~codecat15
*/

struct Bank
{
var accountBalance: Double
{
didSet
{
sendMessageToUser()
}
willSet (newAccountBalance)
{

}
}

mutating func addMoney(amount: Double){
accountBalance += amount
}

mutating func withDrawMoney(amount: Double){
accountBalance -= amount
}

func sendMessageToUser()
{
debugPrint("Account balance updated new balance = \(accountBalance)")
}
}

var bank = Bank(accountBalance: 10000)
bank.addMoney(amount: 5000)


/*class Bank
{
var accountBalance: Double
{
didSet
{
sendMessageToUser()
}
willSet (newAccountBalance)
{
if(newAccountBalance >= 10000000)
{
sendMessageToAuditor()
}
}
}

init(_openingBalance: Double) {
accountBalance = _openingBalance
}

func addMoney(amount: Double){
accountBalance += amount
}

func withDrawMoney(amount: Double){
accountBalance -= amount
}

func sendMessageToUser()
{
debugPrint("Account balance updated new balance = \(accountBalance)")
}

func sendMessageToAuditor()
{
debugPrint("Please check this account, and make sure the transaction is authentic")
}
}

let bank = Bank(_openingBalance: 10000)
bank.addMoney(amount: 50000000)*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ravirdixit/Desktop/MyPlayground.playground#CharacterRangeLen=1718&amp;CharacterRangeLoc=12&amp;EndingColumnNumber=0&amp;EndingLineNumber=79&amp;StartingColumnNumber=12&amp;StartingLineNumber=0&amp;Timestamp=599801075.443302"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "file:///Users/ravirdixit/Desktop/MyPlayground.playground#CharacterRangeLen=1718&amp;CharacterRangeLoc=12&amp;EndingColumnNumber=0&amp;EndingLineNumber=79&amp;StartingColumnNumber=12&amp;StartingLineNumber=0&amp;Timestamp=599801075.443424"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>

0 comments on commit f163b72

Please sign in to comment.