This file contains hidden or 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
| Create a new Data Model file: "CoreDataExample.xcdatamodeld" | |
| Once inside add a new entity and attributes: | |
| ENTITIES: | |
| Student | |
| ATTRIBUTE: | |
| id: UUID | |
| firstName: String | |
| lastName: String |
This file contains hidden or 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
| import SwiftUI | |
| // MARK: CORE DATA MODEL | |
| /* | |
| ENTITY: ShipEntity | |
| ATTRIBUTES: | |
| name: String | |
| universe: String | |
| */ |
This file contains hidden or 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
| First create your data model file: "CoreDataExample.xcdatamodeld" and add this two entities: | |
| 1. | |
| ENTITY: "CountryEntity" | |
| ATTRIBUTES: | |
| shortName: String | |
| fullName: String | |
| NOTE: While having Country Entity selected, Open Data Model Inspector on the right side of the screen and add "shortName" | |
| constraint, this is because this property must be unique. |
This file contains hidden or 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
| First create a data model file: "CoreDataExample.xcdatamodeld", once inside create this entity with this attributes: | |
| ENTITY: "SingerEntity" | |
| ATTRIBUTES: | |
| firstName: String | |
| lastName: String | |
| Now let's generate a class of our entity manually so that we don't have to deal with optionals, like this: | |
| 1. While having "SingerEntity" selected, open the Data Model inspector on the right side of the screen and change Codegen | |
| from "Class Definition" to "Manual/None" |
This file contains hidden or 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
| // To test this code: Run the simulator, tap request permission and grant it. | |
| // Now tap schedule notification and lock the screen, the notification should appear in 5 seconds | |
| import SwiftUI | |
| import UserNotifications | |
| struct LocalNotifications: View { | |
| var body: some View { | |
| VStack { | |
| Button("Request Permission") { |
This file contains hidden or 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
| First open Create ML App: | |
| 1. Go to Xcode/Open Developer Tool/Create ML. In the prompt click New Document | |
| 2. Choose a template: "Tabular Regression" in this case and click Next. | |
| 3. Give it a project name "BetterRest" in this case, click Next and save the project. | |
| Now we need to provide training data to our ML, you can use this sample data from Hacking with swift: | |
| https://github.com/twostraws/HackingWithSwift/blob/main/SwiftUI/project4-files/BetterRest.csv | |
| This is a spreadsheet with 10.000 samples of 4 values: | |
| 1. When someone want to wakeup | |
| 2. How much sleep they want to have |
This file contains hidden or 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
| func gcd(_ a: Int, _ b: Int) -> Int { | |
| var a = a | |
| var b = b | |
| while b != 0 { | |
| let temp = b | |
| b = a % b | |
| a = temp | |
| } | |
| return a |
This file contains hidden or 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
| // Note: to actually see the result of this code please use the iPhone 13 Pro Max simulator or any Plus device | |
| // Since these are the ones with the largest screens. | |
| import SwiftUI | |
| struct UserView: View { | |
| var body: some View { | |
| Group { | |
| Text("Name: Andrés") | |
| Text("Country: Colombia") | |
| Text("Pets: No pets at the moment!") |
This file contains hidden or 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
| // Note: you can change the text size directly from Xcode going to the Environment Override button, on the bottom side of the screen. | |
| struct UserView: View { | |
| var body: some View { | |
| Group { | |
| Text("Name: Andrés") | |
| Text("Country: Colombia") | |
| Text("Pets: No pets") | |
| } | |
| } | |
| } |