Education

RSS for tag

Teach students of all ages to code in Swift using a variety of resources in your curriculum.

Posts under Education tag

117 Posts

Post

Replies

Boosts

Views

Activity

How can I input some commands into terminal in Swift like this?
that is my python code (file name pythonTest.py) while True: a = input() print(a) I want to run this python code in a swift script and get the result. For example, I would like to enter something command like this. python3 pythonTest.py\n1\n2\n3\n and ctrl + C i found Process() but this is only entered once and I don't know how to handle input(), ctrl + C How can I do that? If it's not possible in Swift, is it possible in Python?
0
0
1.2k
Mar ’23
How to make sure that only one video will be played at a time?
Hello there, I created an AR App that plays a video on a particular image anchor. I wanted to extend that application to deal with more than 1 image. Now when I scan 1st image it plays the video, and when I scan the 2nd image it plays another video. The Problem that occurs here is both videos are playing simultaneously. The Code: func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { let node = SCNNode() if let imageAnchor = anchor as? ARImageAnchor { //below code needs to be duplicated in order to add more news if imageAnchor.referenceImage.name == "harrypotter" { let videoNode = SKVideoNode(fileNamed: "harrypotter.mp4") videoNode.play() let videoScene = SKScene(size: CGSize(width: 480, height: 360)) videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2) videoNode.yScale = -1.0 videoScene.addChild(videoNode) let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height) plane.firstMaterial?.diffuse.contents = videoScene let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) } if imageAnchor.referenceImage.name == "deatheater" { let videoNode = SKVideoNode(fileNamed: "deatheater.mp4") videoNode.play() let videoScene = SKScene(size: CGSize(width: 480, height: 360)) videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2) videoNode.yScale = -1.0 videoScene.addChild(videoNode) let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height) plane.firstMaterial?.diffuse.contents = videoScene let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) }
2
1
798
Feb ’23
Announcing App Development with Swift Certification
As you prepare your students for a future driven by technology, teaching them how to code is critical. It opens new doors to potential careers and helps prepare them for college. Starting this school year students can earn App Development with Swift certification through Certiport based on the free App Development with Swift course from Apple. Level 1 certification recognizes knowledge of the Swift programming language, app developer tools, and core components of apps, and can be offered by any Certiport Authorized Testing Center that has purchased access to it.* Students who pass the exam will earn a digital badge to showcase their achievement on a resume, portfolio, email signature, or career networking site.Learn more about App Development with Swift certification at Certiport.com >*Additional terms may apply; see the Certiport website for more information.
3
0
17k
Feb ’23
Is this bad practice?
I am a “newbie” to Coding and Swift. To better understand the Code I have started breaking it up into chunks and formatting as per my example below. My questions are 1) is “Is this bad practice”? 2) “Is it likely to lead to problems later on”? let location = LocationHelper.currentLocation class LocationHelper: NSObject, ObservableObject {      static let shared = LocationHelper() static let DefaultLocation = CLLocationCoordinate2D( latitude: ( thisCardPositionLatidude), longitude: ( thisCardPositionLongitude)) static var currentLocation: CLLocationCoordinate2D { guard let location = shared.locationManager.location else { return DefaultLocation } return location.coordinate }      private let locationManager = CLLocationManager()      private override init() { super.init() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() } } extension LocationHelper: CLLocationManagerDelegate {      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { }      public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Location manager failed with error: \(error.localizedDescription)") }      public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { print("Location manager changed the status: \(status)") } }
6
0
2k
Feb ’23
Why does it return to the console like this?
Could someone explain why the code below: let artists = ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] let durations = [90, 200, 150, 440] func songInformation(title: String, artist: String, duration: Int) -> String {     return "The song is called \(songTitles) by \(artists) and is \(durations) seconds long" } for i in 0 ... songTitles.count - 1 {     print(songInformation(title: songTitles[i], artist: artists[i], duration: durations[i])) } returns the following to the console: The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long I was expecting it to return something more like: The song is called Ooh yeah by Brenda and the Del-Chords and is 90 seconds long.
1
0
740
Feb ’23
I hava a problem
hi, i am a new member to the group, sorry if i wrote wrong, first of all, i am learning swift and i ran into a problem, can you help me?I want to add 6 images into the "var" variable and I get an error. I use the code I wrote before, but it doesn't work. imageOne.image = imageLiteral
2
0
1.2k
Jan ’23
Swift Basic Understanding
Hello Everyone I am new to swift and i am learning from scratch so sorry if I am having hard time to understand, I have this code down here and I don't get why it prints every time i set a value to progress.amount even though I don't call print or even the struct (Note:I have experienced other languages like c# and c): import Foundation struct Progress {   var task: String   var amount: Int{     didSet {       print("(task) is now (amount)% Complete")     }   } } var progress = Progress(task: "Loading Data", amount: 0) progress.amount = 50 progress.amount = 99 progress.amount = 100 And as a newbie to swift which projects would you suggest me to make to improve my skills, I would be glad to learn swiftui too if necessary
2
0
868
Dec ’22
Button to navigate through SwiftUI Views
this is my code I need my toolBar buttons to navigate to other SwiftUi views what should I write in button action { } to open the other SwiftUi View //  SwiftLoginView.swift //  Login FireBase // //  Created by Makwin Santhosh K on 08/11/22. // import SwiftUI import MapKit import CoreLocationUI struct OverallView: View {     var body: some View{                  NavigationView {             ZStack{                                  ToolBarShape()                     .frame(width: 400,height: 110)                     .foregroundColor(.white)                     .shadow(radius: 6)                     .offset(x : 0, y: 410)                                                     .toolbar {                         ToolbarItemGroup(placement: .bottomBar){                             //MARK: Button Home                             Button(action :{                                                              }, label:{                                 VStack {                                     Image(systemName: "house")                                     Text("Home")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Money                             Button(action :{                                                            },label:{                                 VStack {                                     Image(systemName: "dollarsign")                                     Text("Money")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Home                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "person")                                     Text("Help")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                             //MARK: Button Home                             Spacer()                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "menubar.rectangle")                                     Text("More")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                                                                                   }                                              }             }         }     } }      struct MapUView: View {     @StateObject public var ViewModel = ContentViewModal()          var body: some View {         ZStack(alignment: .bottom) {             AreaMap(region: $ViewModel.region)                          LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)              }     }                                   struct AreaMap: View {         @Binding var region: MKCoordinateRegion                  var body: some View {             let binding = Binding(                 get: { self.region },                 set: { newValue in                     DispatchQueue.main.async {                         self.region = newValue                     }                 }             )             return Map(coordinateRegion: binding, showsUserLocation: true)                 .ignoresSafeArea()         }     }               final class ContenViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{         @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 20, longitude: 90), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))         let locationManager = CLLocationManager()                  override init() {             super.init()             locationManager.delegate = self         }                  func requestUserLocationForOnce() {             locationManager.requestLocation()         }                  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {             guard let latestLocation = locations.first else {                 //show error                 return             }             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }                  func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {             print(error.localizedDescription)         }     } } struct OverallView_Previews: PreviewProvider {     static var previews: some View {         OverallView()     } }
5
0
5.2k
Nov ’22
array index confusion
Hello, I am curently study the Apple book "Develop in Swift EXPLORATION" and here is something I don't understand: at page 392, there is this advice, of how to populate a segmentedControl with some emoji, each emoji being previously saved in the elements of "topChoices" array. Here is how the book advice to proceed: for choice in topChoices { topCaptionSegmentedControl.insertSegment(withTitle: choice.emoji, at: topChoices.count,animated: false) } My confusion come from the fact that although the property "count" means the number of elements in that array, in this above case, it seems that topChoices . count means each index, from zero to the last element (because the segmentedControl is populated with each emoji saved in topChoices elements). If topChoices.count means the number of elements in the topChoices array, that implies the segmentedControl would have been populated ONLY with the emoji being saved in the last element of the topChoices array. But, the segmentsControl gets populated with all emojis from the topChoices array. How is that? Thank you!
2
0
790
Oct ’22
How to open settings programmatically in Swift
import SwiftUI struct ButtonUI: View {     var body: some View {                      ZStack {                                  Color.white             RoundedRectangle(cornerRadius: 50)                     .fill(.blue)                     .frame(width: 250, height: 75, alignment: .center)                                  Text("Enable Location")                     .font(.title3)                     .fontWeight(.bold)                     .foregroundColor(Color.white)                              }             .offset(x: 0, y: 300)     } } struct ButtonUI_Previews: PreviewProvider {     static var previews: some View {         ButtonUI()     } } // I have used this code to create a button like shape in Xcode how to do i make it work like open the location settings in iPhone // it should work like a button to open the location settings in iPhone
3
0
7.3k
Oct ’22
Develop In Swift Explorations - Unit 1 Build
In Part 1 of Unit 1 Build Students must set up the project using the App template feature. On page 55 the viewer window shows in the left column a list of files that should be in the photo frame. These include: AppDelegate, SceneDelegate, ViewController, Main, Assets and LaunchScreen. I can see this on my computer, however when my students follow the same steps. They only see the files name ad ContentView What are we doing wrong?!
3
0
836
Oct ’22
Use cases for closures vs. functions
I've been learning Swift for the last couple weeks on the weekends and I understand, from what I've read, that functions are basically closures. But, this confuses me because obviously a feature thats 100% redundant wouldn't be implemented, so when should you use closures vs functions? Are there times you can only use closures in Swift, or can you always use them interchangeably?
2
0
1.2k
Oct ’22
Swift Exercise: Leap Years
Hello! I can't understand what am I supposed to do in this exercise. Can someone walk me through? Exercise: Leap Years To decide if a year is a leap year, there are several decisions that have to be made in the correct order. Is the year divisible by 4? If so, is the year divisible by 100? If so, is the year divisible by 400? If so, it is a leap year. If not, it is not a leap year. If it's not divisible by 100, it is a leap year. If it's not divisible by 4, it is not a leap year. These decisions can be made inside a function as a series of nested if...else statements. The number(_:, isDivisibleBy:) function has been built into this playground to make this exercise easier. Below is an incomplete function for deciding if a given year is a leap year: func isLeapYear(_ year: Int) -> Bool {     // Is the year divisible by 4?     if number(year, isDivisibleBy: 4) {         return true     } else {         return false      } // Should be true isLeapYear(2000) // Should be false isLeapYear(1900) // Should be true isLeapYear(2012) // Should be false isLeapYear(2017) Exercise Complete the function above so that the rules are all followed and the examples get the correct answers.  Hint: Try using the rules as pseudocode by making them into comments. Then write the code that goes with each comment underneath it. Exercise For a challenge, complete the function below. It should behave identically without using any nested conditional statements. Use a single level of if/else statements along with conditionals that use Boolean operators.  Hint: Create constants that represent the three key conditions, and then compose a Boolean expression with those constants. func isLeapYear2(_ year: Int) -> Bool { }
2
0
2.7k
Oct ’22
Develop in Swift Explorations/Xcode 13: downloaded lessons not loading while working on programming files
Hello I am teaching xCode using the textbook Develop in Swift Explorations/Xcode 13.  We're using the associated lessons in the xCode Dev environment.  We're having issues with the lessons not completely loading - the results panel is blank. We've tried restarting the program, the computer, and toggling to the previous lesson within the program to try and get it to reload. Nothing resolves it. The files have been downloaded. Perhaps they take alot of RAM to run, and the computers are full? I've looked at the RAM and seem to have enough, but maybe not? Help/advice appreciated.
0
0
843
Oct ’22
"Could not display guide" message
I created a swiftpm project with Xcode Version 13.4.1 (13F100). I changed the target from the default created by Xcode to this:     targets: [         .executableTarget(             name: "App",             path: "App"         )     ] I also changed the package version to 5.6 to match the AboutMe Package file. I also created an App directory and moved all my files (bar the Package.swift file) to it, and I also created a Guide folder and created a Guide.tutorial file based on the example in the WWDC video. I've turned on Author Debugging Mode (this is on Swift Playgrounds on the Mac, I'll try later on Swift Playgrounds on the iPad), but I get no messages other than the "Could not display guide. Try reopening the current project..." I also get a build error that just says "Building failed" What am I missing?
2
0
2.6k
Sep ’22
How can I input some commands into terminal in Swift like this?
that is my python code (file name pythonTest.py) while True: a = input() print(a) I want to run this python code in a swift script and get the result. For example, I would like to enter something command like this. python3 pythonTest.py\n1\n2\n3\n and ctrl + C i found Process() but this is only entered once and I don't know how to handle input(), ctrl + C How can I do that? If it's not possible in Swift, is it possible in Python?
Replies
0
Boosts
0
Views
1.2k
Activity
Mar ’23
Student challenge submission?
Is the student challenge submission must need to run on the iPad or it can only run on iPhone?
Replies
1
Boosts
0
Views
1.6k
Activity
Feb ’23
How to make sure that only one video will be played at a time?
Hello there, I created an AR App that plays a video on a particular image anchor. I wanted to extend that application to deal with more than 1 image. Now when I scan 1st image it plays the video, and when I scan the 2nd image it plays another video. The Problem that occurs here is both videos are playing simultaneously. The Code: func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { let node = SCNNode() if let imageAnchor = anchor as? ARImageAnchor { //below code needs to be duplicated in order to add more news if imageAnchor.referenceImage.name == "harrypotter" { let videoNode = SKVideoNode(fileNamed: "harrypotter.mp4") videoNode.play() let videoScene = SKScene(size: CGSize(width: 480, height: 360)) videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2) videoNode.yScale = -1.0 videoScene.addChild(videoNode) let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height) plane.firstMaterial?.diffuse.contents = videoScene let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) } if imageAnchor.referenceImage.name == "deatheater" { let videoNode = SKVideoNode(fileNamed: "deatheater.mp4") videoNode.play() let videoScene = SKScene(size: CGSize(width: 480, height: 360)) videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2) videoNode.yScale = -1.0 videoScene.addChild(videoNode) let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height) plane.firstMaterial?.diffuse.contents = videoScene let planeNode = SCNNode(geometry: plane) planeNode.eulerAngles.x = -.pi / 2 node.addChildNode(planeNode) }
Replies
2
Boosts
1
Views
798
Activity
Feb ’23
Announcing App Development with Swift Certification
As you prepare your students for a future driven by technology, teaching them how to code is critical. It opens new doors to potential careers and helps prepare them for college. Starting this school year students can earn App Development with Swift certification through Certiport based on the free App Development with Swift course from Apple. Level 1 certification recognizes knowledge of the Swift programming language, app developer tools, and core components of apps, and can be offered by any Certiport Authorized Testing Center that has purchased access to it.* Students who pass the exam will earn a digital badge to showcase their achievement on a resume, portfolio, email signature, or career networking site.Learn more about App Development with Swift certification at Certiport.com >*Additional terms may apply; see the Certiport website for more information.
Replies
3
Boosts
0
Views
17k
Activity
Feb ’23
Is this bad practice?
I am a “newbie” to Coding and Swift. To better understand the Code I have started breaking it up into chunks and formatting as per my example below. My questions are 1) is “Is this bad practice”? 2) “Is it likely to lead to problems later on”? let location = LocationHelper.currentLocation class LocationHelper: NSObject, ObservableObject {      static let shared = LocationHelper() static let DefaultLocation = CLLocationCoordinate2D( latitude: ( thisCardPositionLatidude), longitude: ( thisCardPositionLongitude)) static var currentLocation: CLLocationCoordinate2D { guard let location = shared.locationManager.location else { return DefaultLocation } return location.coordinate }      private let locationManager = CLLocationManager()      private override init() { super.init() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() } } extension LocationHelper: CLLocationManagerDelegate {      func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { }      public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("Location manager failed with error: \(error.localizedDescription)") }      public func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) { print("Location manager changed the status: \(status)") } }
Replies
6
Boosts
0
Views
2k
Activity
Feb ’23
Why does it return to the console like this?
Could someone explain why the code below: let artists = ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] let durations = [90, 200, 150, 440] func songInformation(title: String, artist: String, duration: Int) -> String {     return "The song is called \(songTitles) by \(artists) and is \(durations) seconds long" } for i in 0 ... songTitles.count - 1 {     print(songInformation(title: songTitles[i], artist: artists[i], duration: durations[i])) } returns the following to the console: The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long The song is called ["Ooh yeah", "Maybe", "No, no, no", "Makin\' up your mind"] by ["Brenda and the Del-chords", "Brenda and the Del-chords", "Fizz", "Boom!"] and is [90, 200, 150, 440] seconds long I was expecting it to return something more like: The song is called Ooh yeah by Brenda and the Del-Chords and is 90 seconds long.
Replies
1
Boosts
0
Views
740
Activity
Feb ’23
stop running the shortcut while it's working
i want to make a choose menu to stop shortcut while it's working (play sound) so it's gonna look like alarm in clock when it's ringing there's a button to stop but i don't know how to make this code in shortcut
Replies
0
Boosts
0
Views
694
Activity
Jan ’23
Please Help Me Fix This Issues
Here is my whole code, does someone knows how to fix it?
Replies
7
Boosts
0
Views
1.3k
Activity
Jan ’23
I hava a problem
hi, i am a new member to the group, sorry if i wrote wrong, first of all, i am learning swift and i ran into a problem, can you help me?I want to add 6 images into the "var" variable and I get an error. I use the code I wrote before, but it doesn't work. imageOne.image = imageLiteral
Replies
2
Boosts
0
Views
1.2k
Activity
Jan ’23
Swift Basic Understanding
Hello Everyone I am new to swift and i am learning from scratch so sorry if I am having hard time to understand, I have this code down here and I don't get why it prints every time i set a value to progress.amount even though I don't call print or even the struct (Note:I have experienced other languages like c# and c): import Foundation struct Progress {   var task: String   var amount: Int{     didSet {       print("(task) is now (amount)% Complete")     }   } } var progress = Progress(task: "Loading Data", amount: 0) progress.amount = 50 progress.amount = 99 progress.amount = 100 And as a newbie to swift which projects would you suggest me to make to improve my skills, I would be glad to learn swiftui too if necessary
Replies
2
Boosts
0
Views
868
Activity
Dec ’22
where can i find the lab material for the iBook App Development with Swift?
going thru the iBook App Development with Swift. I can not find the lab files for the book. for example: where is the Lab-Enumerations.playground files? Search just shows a GitHub...
Replies
4
Boosts
0
Views
6.2k
Activity
Nov ’22
Button to navigate through SwiftUI Views
this is my code I need my toolBar buttons to navigate to other SwiftUi views what should I write in button action { } to open the other SwiftUi View //  SwiftLoginView.swift //  Login FireBase // //  Created by Makwin Santhosh K on 08/11/22. // import SwiftUI import MapKit import CoreLocationUI struct OverallView: View {     var body: some View{                  NavigationView {             ZStack{                                  ToolBarShape()                     .frame(width: 400,height: 110)                     .foregroundColor(.white)                     .shadow(radius: 6)                     .offset(x : 0, y: 410)                                                     .toolbar {                         ToolbarItemGroup(placement: .bottomBar){                             //MARK: Button Home                             Button(action :{                                                              }, label:{                                 VStack {                                     Image(systemName: "house")                                     Text("Home")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Money                             Button(action :{                                                            },label:{                                 VStack {                                     Image(systemName: "dollarsign")                                     Text("Money")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                              })                             Spacer()                             //MARK: Button Home                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "person")                                     Text("Help")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                             //MARK: Button Home                             Spacer()                             Button(action :{                                                              },label:{                                 VStack {                                     Image(systemName: "menubar.rectangle")                                     Text("More")                                 }                                 .font(.footnote)                                 .foregroundColor(.black)                                                                                               })                                                                                   }                                              }             }         }     } }      struct MapUView: View {     @StateObject public var ViewModel = ContentViewModal()          var body: some View {         ZStack(alignment: .bottom) {             AreaMap(region: $ViewModel.region)                          LocationButton(.currentLocation){                 ViewModel.requestUserLocationForOnce()             }             .foregroundColor(.white)             .cornerRadius(8)              }     }                                   struct AreaMap: View {         @Binding var region: MKCoordinateRegion                  var body: some View {             let binding = Binding(                 get: { self.region },                 set: { newValue in                     DispatchQueue.main.async {                         self.region = newValue                     }                 }             )             return Map(coordinateRegion: binding, showsUserLocation: true)                 .ignoresSafeArea()         }     }               final class ContenViewModal: NSObject, ObservableObject, CLLocationManagerDelegate{         @Published var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 20, longitude: 90), span: MKCoordinateSpan(latitudeDelta: 100, longitudeDelta: 100))         let locationManager = CLLocationManager()                  override init() {             super.init()             locationManager.delegate = self         }                  func requestUserLocationForOnce() {             locationManager.requestLocation()         }                  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {             guard let latestLocation = locations.first else {                 //show error                 return             }             self.region = MKCoordinateRegion(center: latestLocation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))         }                  func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {             print(error.localizedDescription)         }     } } struct OverallView_Previews: PreviewProvider {     static var previews: some View {         OverallView()     } }
Replies
5
Boosts
0
Views
5.2k
Activity
Nov ’22
array index confusion
Hello, I am curently study the Apple book "Develop in Swift EXPLORATION" and here is something I don't understand: at page 392, there is this advice, of how to populate a segmentedControl with some emoji, each emoji being previously saved in the elements of "topChoices" array. Here is how the book advice to proceed: for choice in topChoices { topCaptionSegmentedControl.insertSegment(withTitle: choice.emoji, at: topChoices.count,animated: false) } My confusion come from the fact that although the property "count" means the number of elements in that array, in this above case, it seems that topChoices . count means each index, from zero to the last element (because the segmentedControl is populated with each emoji saved in topChoices elements). If topChoices.count means the number of elements in the topChoices array, that implies the segmentedControl would have been populated ONLY with the emoji being saved in the last element of the topChoices array. But, the segmentsControl gets populated with all emojis from the topChoices array. How is that? Thank you!
Replies
2
Boosts
0
Views
790
Activity
Oct ’22
How to open settings programmatically in Swift
import SwiftUI struct ButtonUI: View {     var body: some View {                      ZStack {                                  Color.white             RoundedRectangle(cornerRadius: 50)                     .fill(.blue)                     .frame(width: 250, height: 75, alignment: .center)                                  Text("Enable Location")                     .font(.title3)                     .fontWeight(.bold)                     .foregroundColor(Color.white)                              }             .offset(x: 0, y: 300)     } } struct ButtonUI_Previews: PreviewProvider {     static var previews: some View {         ButtonUI()     } } // I have used this code to create a button like shape in Xcode how to do i make it work like open the location settings in iPhone // it should work like a button to open the location settings in iPhone
Replies
3
Boosts
0
Views
7.3k
Activity
Oct ’22
Develop In Swift Explorations - Unit 1 Build
In Part 1 of Unit 1 Build Students must set up the project using the App template feature. On page 55 the viewer window shows in the left column a list of files that should be in the photo frame. These include: AppDelegate, SceneDelegate, ViewController, Main, Assets and LaunchScreen. I can see this on my computer, however when my students follow the same steps. They only see the files name ad ContentView What are we doing wrong?!
Replies
3
Boosts
0
Views
836
Activity
Oct ’22
Use cases for closures vs. functions
I've been learning Swift for the last couple weeks on the weekends and I understand, from what I've read, that functions are basically closures. But, this confuses me because obviously a feature thats 100% redundant wouldn't be implemented, so when should you use closures vs functions? Are there times you can only use closures in Swift, or can you always use them interchangeably?
Replies
2
Boosts
0
Views
1.2k
Activity
Oct ’22
Swift Exercise: Leap Years
Hello! I can't understand what am I supposed to do in this exercise. Can someone walk me through? Exercise: Leap Years To decide if a year is a leap year, there are several decisions that have to be made in the correct order. Is the year divisible by 4? If so, is the year divisible by 100? If so, is the year divisible by 400? If so, it is a leap year. If not, it is not a leap year. If it's not divisible by 100, it is a leap year. If it's not divisible by 4, it is not a leap year. These decisions can be made inside a function as a series of nested if...else statements. The number(_:, isDivisibleBy:) function has been built into this playground to make this exercise easier. Below is an incomplete function for deciding if a given year is a leap year: func isLeapYear(_ year: Int) -> Bool {     // Is the year divisible by 4?     if number(year, isDivisibleBy: 4) {         return true     } else {         return false      } // Should be true isLeapYear(2000) // Should be false isLeapYear(1900) // Should be true isLeapYear(2012) // Should be false isLeapYear(2017) Exercise Complete the function above so that the rules are all followed and the examples get the correct answers.  Hint: Try using the rules as pseudocode by making them into comments. Then write the code that goes with each comment underneath it. Exercise For a challenge, complete the function below. It should behave identically without using any nested conditional statements. Use a single level of if/else statements along with conditionals that use Boolean operators.  Hint: Create constants that represent the three key conditions, and then compose a Boolean expression with those constants. func isLeapYear2(_ year: Int) -> Bool { }
Replies
2
Boosts
0
Views
2.7k
Activity
Oct ’22
Develop in Swift Explorations/Xcode 13: downloaded lessons not loading while working on programming files
Hello I am teaching xCode using the textbook Develop in Swift Explorations/Xcode 13.  We're using the associated lessons in the xCode Dev environment.  We're having issues with the lessons not completely loading - the results panel is blank. We've tried restarting the program, the computer, and toggling to the previous lesson within the program to try and get it to reload. Nothing resolves it. The files have been downloaded. Perhaps they take alot of RAM to run, and the computers are full? I've looked at the RAM and seem to have enough, but maybe not? Help/advice appreciated.
Replies
0
Boosts
0
Views
843
Activity
Oct ’22
Swift Playgrounds: How to change language
I just installed Swift Playgrounds on my ipad. It comes in English, probably because that is the language to which the ipad is set, but my children are more comfortable in Japanese. How can I switch to Japanese?
Replies
2
Boosts
0
Views
5.9k
Activity
Oct ’22
"Could not display guide" message
I created a swiftpm project with Xcode Version 13.4.1 (13F100). I changed the target from the default created by Xcode to this:     targets: [         .executableTarget(             name: "App",             path: "App"         )     ] I also changed the package version to 5.6 to match the AboutMe Package file. I also created an App directory and moved all my files (bar the Package.swift file) to it, and I also created a Guide folder and created a Guide.tutorial file based on the example in the WWDC video. I've turned on Author Debugging Mode (this is on Swift Playgrounds on the Mac, I'll try later on Swift Playgrounds on the iPad), but I get no messages other than the "Could not display guide. Try reopening the current project..." I also get a build error that just says "Building failed" What am I missing?
Replies
2
Boosts
0
Views
2.6k
Activity
Sep ’22