kenny lemon
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# CS193P - Lecture 2: Learing more about SwiftUI - 85 mins * Demo code at cs193p.stanford.edu * How-to and How-things-work course * How SwiftUI is doing what it’s doing * Prerequisites for student for this course is at least 3 and recommend 4 intro CS courses. * They are relatively experienced programmers. * Object-oriented programming * Swift # ## [00:00](https://youtu.be/3lahkdHEhW8&t=0m0s) * Let us start by just making a single row card.![](https://i.imgur.com/FvKroMR.png) * [04:15](https://youtu.be/3lahkdHEhW8&t=4m15s) * refactor the cardView as a new structure![](https://i.imgur.com/psFOd3r.png) * .preferredColorScheme(.dark) in previews * [08:30](https://youtu.be/3lahkdHEhW8&t=8m30s) * You can display both dark and light mode cases in preview![](https://i.imgur.com/TTi0YOD.png) # ## [11:30](https://youtu.be/3lahkdHEhW8&t=11m30s) * How to make the card flip * [13:10](https://youtu.be/3lahkdHEhW8&t=13m10s) The initiation of CardView raise error. You cannot have vairables that have no value. (optional will be mentioned in lecture 3) * [18:30](https://youtu.be/3lahkdHEhW8&t=18m30s) There are multiple code snippet duplicated, RoundedRectangle(cornerRadius: 20), and we can create a local variable ``` swift var shape = RoundedRectangle(cornerRadius:20) ``` to replace the redundant code snippet. * To fix the warning about changing the declaration of shape from **var** to **let**. * **var** is going to be a variable. and **let** for constant. * [22:15](https://youtu.be/3lahkdHEhW8&t=22m15s) animation to make the card flip over. * Using Tap gesture as a view modifier. * Add @State to make the boolean a pointer instead of making it an mutable variable. * Whenever **isFaceUp** changes, SwiftUI is smart enough to get to know the system need to rebuild this view, and then it will re-create the body. * [31:30](https://youtu.be/3lahkdHEhW8&t=31m30s) Option+click to check out the documentation. * Also, you can use command+Shift+O to open **Developer Documentation** * Tips, you can use comman+option+Space to open **Emoji & symbols** # ## [35:00](https://youtu.be/3lahkdHEhW8&t=35m00s) Using Array to handle String * There are 3 ways to declare an array ```swift= var emoji: Array<String> = [xxx] var emoji: [String] = [xxx] var emoji = [xxx] // swift type inference ``` * you can use Option+click to find out the type of the vairable. * Error: Referencing initializer `init(_:content:)` on `ForEach` requires that `String` conform to `identifiable` * Which means the item need to have a uniquiely id that can identify it. * ![](https://i.imgur.com/gXIKlpU.png) # ## [45:50](https://youtu.be/3lahkdHEhW8&t=45m50s) To add or remove cars * A range of an Array ```swift emojis[0..<6] // first 6 items ``` * add a add button and a remove button. * To download [SF-Symbols](https://developer.apple.com/sf-symbols/), all you need to know is the name. # ## [01:10:00](https://youtu.be/3lahkdHEhW8&t=1h10m00s) Turn this into a grid * Why does the LazyVGrid make the cardView a small one? * The card view in HStack or VStack is much taller and much more like a card. * HStack/VStack strategy is to uses all the space in both height and width it can * LazyVGrid strategy is to use all the width horizontally for its column, but as small as possible vertically. So it can fit as many as possible in to the grid. * Using HStack ![](https://i.imgur.com/jtKsTb2.png) * Using LazyVGrid ![](https://i.imgur.com/pYLaLao.png) * Difference when Spacer() along with HStack and LazyVGrid |HStack | ![](https://i.imgur.com/jDiim9N.png )| ![](https://i.imgur.com/Z42743n.png)| | --------| -------- | -------- | |LazyVGrid |![](https://i.imgur.com/4HmTldG.png) |![](https://i.imgur.com/WRDCB5Q.png)| | --------| -------- | -------- | * LazyVGrid, lets you specify a number of columns. * The word **Lazy** is lazy about accesing the body vars of all of its Views, e.g. CarView in this case. * Make GridItem() in an array as the input, GidItems make you controls the columns more, e.g. give the column with 200 fixed width. * GridItem make you control the columns more. * e.g. * GridItem(.fixed(200)) * GridItem(.flexible()), flex to whatever space is available. -> the default setup # ## [01:19:10](https://youtu.be/3lahkdHEhW8&t=1h19m10s) Our card is actually getting slightly cut off. * The goal of the line is to shows up inside the card area, though it is on teh card boundary. ```swift= Card.stroke(linewidth: 4) ``` | ![](https://i.imgur.com/WIqVyIe.png)| ![](https://i.imgur.com/0hNpTq1.png)| | -------- | -------- | * To fix this problem, we use **StokeBorder** to make the border stroking on the inside. ```swift= Card.strokeBorder(linewidth: 4) ``` | ![](https://i.imgur.com/xt3QiPM.png) | ![](https://i.imgur.com/LuQp2Cz.png) | | -------- | -------- | # ## [01:21:00](https://youtu.be/3lahkdHEhW8&t=1h21m00s) To show more card when the device is in landscape mode. * LazyVGrid, Griditem(.adpative(minimim: 65)) * This setup tells LazyVGrid to put as many cards in each row if possible.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully