forked from codecat15/Youtube-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
Properties/Property wrappers/MyPlayground.playground/Contents.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import UIKit | ||
|
||
/* Thank you for downloading the code, I hope the video on property wrapper helped you and if you have any questions then please feel free to ask them on the channel as a comment OR as email, My email Id is mentioned in the code :) | ||
Do subscribe to the channel and share it with your friends OR on any social media you like ~codecat15 | ||
*/ | ||
|
||
//extension String | ||
//{ | ||
// func isValidEmail(email: String) -> Bool { | ||
// let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-za-z]{2,64}" | ||
// let pred = NSPredicate(format: "SELF MATCHES %@", regex) | ||
// return pred.evaluate(with: email) | ||
// } | ||
//} | ||
|
||
@propertyWrapper | ||
struct EmailPropertyWrapper | ||
{ | ||
private var _value: String | ||
var wrappedValue: String | ||
{ | ||
get | ||
{ | ||
return isValidEmail(email: _value) ? _value : String() | ||
} | ||
set | ||
{ | ||
_value = newValue | ||
} | ||
} | ||
|
||
init(_emailValue: String) { | ||
_value = _emailValue | ||
} | ||
|
||
private func isValidEmail(email: String) -> Bool { | ||
let regex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-za-z]{2,64}" | ||
let pred = NSPredicate(format: "SELF MATCHES %@", regex) | ||
return pred.evaluate(with: email) | ||
} | ||
} | ||
|
||
struct Employee | ||
{ | ||
@EmailPropertyWrapper var employeeEmailId: String | ||
} | ||
|
||
struct User | ||
{ | ||
var name: String | ||
@EmailPropertyWrapper var email: String | ||
|
||
func validate() -> Bool | ||
{ | ||
if(name.isEmpty || email.isEmpty) | ||
{ | ||
debugPrint("name and a valid email is required and cannot be empty") | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func registerUser() | ||
{ | ||
if(validate()) | ||
{ | ||
//saving user records code... | ||
debugPrint("User data saved") | ||
} | ||
} | ||
} | ||
|
||
let user = User(name: "codecat15", email: EmailPropertyWrapper(_emailValue:"codecat15gmail.com")) | ||
user.registerUser() |
4 changes: 4 additions & 0 deletions
4
Properties/Property wrappers/MyPlayground.playground/contents.xcplayground
This file contains 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
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> |
7 changes: 7 additions & 0 deletions
7
...Property wrappers/MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...pers/MyPlayground.playground/playground.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains 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
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 added
BIN
+9.95 KB
...d/playground.xcworkspace/xcuserdata/ravirdixit.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
16 changes: 16 additions & 0 deletions
16
Properties/Property wrappers/MyPlayground.playground/timeline.xctimeline
This file contains 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
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=1884&CharacterRangeLoc=0&EndingColumnNumber=0&EndingLineNumber=74&StartingColumnNumber=0&StartingLineNumber=0&Timestamp=600486351.617571" | ||
selectedRepresentationIndex = "0" | ||
shouldTrackSuperviewWidth = "NO"> | ||
</LoggerValueHistoryTimelineItem> | ||
<LoggerValueHistoryTimelineItem | ||
documentLocation = "file:///Users/ravirdixit/Desktop/MyPlayground.playground#CharacterRangeLen=1884&CharacterRangeLoc=0&EndingColumnNumber=0&EndingLineNumber=74&StartingColumnNumber=0&StartingLineNumber=0&Timestamp=600486351.617712" | ||
selectedRepresentationIndex = "0" | ||
shouldTrackSuperviewWidth = "NO"> | ||
</LoggerValueHistoryTimelineItem> | ||
</TimelineItems> | ||
</Timeline> |