{"id":27644449,"url":"https://github.com/yeahsilver/swiftui","last_synced_at":"2026-07-17T02:31:21.917Z","repository":{"id":133391678,"uuid":"323917309","full_name":"yeahsilver/SwiftUI","owner":"yeahsilver","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-09T12:13:28.000Z","size":2975,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-17T11:18:20.179Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yeahsilver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-12-23T14:02:10.000Z","updated_at":"2021-07-03T09:17:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"38e025a2-7729-49e7-a677-4dae6e487fb4","html_url":"https://github.com/yeahsilver/SwiftUI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yeahsilver/SwiftUI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeahsilver%2FSwiftUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeahsilver%2FSwiftUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeahsilver%2FSwiftUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeahsilver%2FSwiftUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeahsilver","download_url":"https://codeload.github.com/yeahsilver/SwiftUI/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeahsilver%2FSwiftUI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35564954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-17T02:00:06.162Z","response_time":116,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-24T00:26:45.158Z","updated_at":"2026-07-17T02:31:21.911Z","avatar_url":"https://github.com/yeahsilver.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftUI\n## Creating and Combining Views\n### Create a New Project and Explore the Canvas\n- @main: app's entry point\n\n- By default value, **two** structures are declared in Swift UIView\n  - First Strcture: conform to the *View* protocol and describe view content \u0026 layout\n  - Second Structure: declares a preview for that view\n  \n  \u003c/br\u003e\n\n### Customize the Text View\n- Edit code to change padding and text color\n  ```swift\n  Text(\"Turtle Rock\")\n    .font(.title)\n    .foregroundColor(.green)\n  ```\n- How to open SwiftUI Inspector: `command + click`\n\n\u003c/br\u003e\n\n### Combine Views Using Stacks\n- The reason of view returning only a ***single view***, we can combine and embed multiple views in ***stacks*** which group views together horizontally, vertically, or back-to-front\n\n\n- Use of Vertical Stack: `Embed in VStack`\n  \u003e By default, stacks center their contents along their axis and provide context-appropriate spacing, so we can edit the VStack to align views by their leading edges\n  ```swift\n    VStack(alignment: .leading){\n      Text(\"Turtle Rock\")\n        .font(.title)\n    }\n  ```\n  \n- Use of Horizontal Stack: `Embed in HStack`\n  ```swift\n  Hstack {\n     Text(\"Joshua Tree National Park\")\n      .font(.subheadline)\n     Text(\"California\")\n      .font(.subheadline)\n  }\n  ```\n\n- Full width of the device, separate the elements -\u003e Using `Spacer()`\n  \u003e A *spacer* expands to make its containing view use all of the space of its parent view, instead of having its size defined only by its contents.\n  \n-  To give a little more space, we can use `.padding` at the end of stack\n\n### Create a Custom Image View\n- To place images on the device, we can use `Image(_:` modifier\n- To clip shape cirle, we can call to clipShape(Circle())\n- Create a circle with a gray stroke, and then add it as an overlay to give image border.\n  ```swift\n  Image(\"turtlerock\")\n    .clipShape(Circle())\n    .overlay(Circle().stroke(Color.gray, lineWidth: 4))\n  ```\n\n### Use SwiftUI Views From other Frameworks\n- Add an import statement for Mapkit\n  ```swift\n  import MapKit\n  ```\n\n- Create a private state variable that holds the regin information for the map\n  \u003e You use *@State* attribute to establish a source of truth for data in your app that you can modify from more than on view\n  ```swift\n  @State private var region = MKCoordinateRegion(\n    center: CLLocationCoordinate2D(latitude: 34.011_286, longitude: -116.166_868),\n    span: MKCoordinateSpan(latitudeDelta: 0.2, longitudeDelta: 0.2)\n  )\n  ```\n\n- Takes a bining to the region\n  ```swift\n  var body: some View {\n    Map(coordinateRegion: $region)\n  }\n  ```\n\n\u003c/br\u003e\n\n### Compse the Detail View\n- Add custom MapView to the top of the stack. \n  \u003e Set the size of the MapView with frame(width: height:)\n  \u003e\n  \u003e Add the CircleImage view to the stack\n  ```swift\n  var body: some View {\n    VStack {\n      MapView()\n        .ignoreSafeArea(edges: .top)\n        .frame(height: 300)\n      CircleImage()\n        .offset(y: -130)\n        .padding(.bottom, 130)\n    }\n  }\n  ```\n  \n  \n## Building Lists and Navigation\n### Create a Landmark Model\n\n- Define a Landmark structure\n  ```swift\n  import Foundation\n  import SwiftUI\n  import CoreLocation\n  \n  struct Landmark: Hashable, Codable {\n    var id: Int\n    var name: String\n    var park: String\n    var state: String\n    var description: String\n    \n    private var imageName: String\n    var image: Image {\n      Image(imageName)\n    }\n    \n    private var coordinates: Coordinates\n    var locationCoordinate: CLLocationCoordinate2D {\n      CLLocationCoordinate2D(\n        latitude: coordinates.latitude,\n        longitude: coordinates.longitude\n      )\n    }\n    struct Coordinate: Hashable, Codable {\n      var latitude: Double\n      var longitude: Double\n     }\n  }\n  ```\n\n- Load data\n  ```swift\n  import Foundation\n\n  var landmarks: [Landmark] = load(\"landmarkData.json\")\n\n  func load\u003cT: Decodable\u003e(_ filename: String) -\u003e T {\n      let data: Data\n\n      guard let file = Bundle.main.url(forResource: filename, withExtension: nil)\n      else {\n          fatalError(\"Couldn't find \\(filename) in main bundle.\")\n      }\n\n      do {\n          data = try Data(contentsOf: file)\n      } catch {\n          fatalError(\"Couldn't load \\(filename) from main bundle:\\n\\(error)\")\n      }\n\n      do {\n          let decoder = JSONDecoder()\n          return try decoder.decode(T.self, from: data)\n      } catch {\n          fatalError(\"Couldn't parse \\(filename) as \\(T.self):\\n\\(error)\")\n      }\n  }\n  ```\n\n### Create the Row View\n- Add landmark as a stored property of LandmarkRow\n  ```swift\n  import SwiftUI\n  \n  struct LandmarkRow: View {\n    var landmark: Landmark\n    \n    var body: some View {\n      HStack {\n      landmark.image\n        .resizable()\n        .frame(width: 50, height: 50)\n        Text(landmark.name)\n        \n        Spacer()\n      }\n    }\n  }\n  \n  struct LandmarkRow_Previews: PreviewProvider {\n    static var previews: some View {\n      LandmarkRow(landmark: landmarks[0])\n    }\n  }\n  ```\n\n\u003c/br\u003e\n\n### Customize the Row Preview\n- Wrap the returned row in a Group, and add the first row back again\n  ```swift\n  import SwiftUI\n  \n  struct LandmarkRow: View {\n    var landmark: Landmark\n    \n    var body: some View {\n      HStack {\n      landmark.image\n        .resizable()\n        .frame(width: 50, height: 50)\n        Text(landmark.name)\n        \n        Spacer()\n      }\n    }\n  }\n  \n  struct LandmarkRow_Previews: PreviewProvider {\n    static var previews: some View {\n    Group {\n        LandmarkRow(landmark: landmarks[0])\n        LandmarkRow(landmark: landmarks[1]) \n      }.previewLayout(.fixed(width: 300, height: 70))\n    }\n  }\n  ```\n\n\u003c/br\u003e\n\n### Create the List of Landmarks\n- Create static views\n  ```swift\n  struct LandmarkList: View {\n    var body: some View {\n      List {\n        LandmarkRow(landmark: landmark[0])\n        LandmarkRow(landmark: landmark[1])\n      }\n    }\n  }\n  ```\n\n### Make the List Dynamic\n- We can generate rows directly from a collection\n  ```swift\n  struct LandmarkList: View {\n    var body: some View {\n      List(landmarks){\n        Landmark in LandmarkRow(landmark: landmark)\n      }\n    }\n  }\n  ```\n  \n  \n  ```\n  // Landmark.swift\n  struct Landmark: Hashable, Codable, Identifiable {\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeahsilver%2Fswiftui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeahsilver%2Fswiftui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeahsilver%2Fswiftui/lists"}