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

108 Posts

Post

Replies

Boosts

Views

Activity

Can I apply to attend and submit the application to attend the apple special event & the swift student challenge both at the same time? Or can I only submit one application?
I am writing to inquire whether I am eligible to apply for both the Apple Worldwide Developers Conference (WWDC) special event and the Swift Student Challenge. I am 18 years old and extremely interested in pursuing my passion for programming through these opportunities. As I understand it, the WWDC is an annual conference hosted by Apple for developers to gather and learn about the latest technologies and innovations in their field. On the other hand, the Swift Student Challenge is a program that encourages students to showcase their coding skills by creating a Swift playground. My question is whether it is possible for me to apply for both programs simultaneously. While I am aware that there may be certain eligibility requirements for each program, I believe that I meet the criteria for both. However, I wanted to confirm this with you before submitting my applications. I would appreciate any information or guidance you can provide on this matter. Thank you for your time and attention.
1
1
1.4k
Mar ’23
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.4k
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
1.1k
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
2.3k
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
1k
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.4k
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
1.1k
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.4k
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
1k
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.6k
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
1.1k
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.4k
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.9k
Oct ’22
Can I apply to attend and submit the application to attend the apple special event & the swift student challenge both at the same time? Or can I only submit one application?
I am writing to inquire whether I am eligible to apply for both the Apple Worldwide Developers Conference (WWDC) special event and the Swift Student Challenge. I am 18 years old and extremely interested in pursuing my passion for programming through these opportunities. As I understand it, the WWDC is an annual conference hosted by Apple for developers to gather and learn about the latest technologies and innovations in their field. On the other hand, the Swift Student Challenge is a program that encourages students to showcase their coding skills by creating a Swift playground. My question is whether it is possible for me to apply for both programs simultaneously. While I am aware that there may be certain eligibility requirements for each program, I believe that I meet the criteria for both. However, I wanted to confirm this with you before submitting my applications. I would appreciate any information or guidance you can provide on this matter. Thank you for your time and attention.
Replies
1
Boosts
1
Views
1.4k
Activity
Mar ’23
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.4k
Activity
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) }
Replies
2
Boosts
1
Views
1.1k
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
2.3k
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
1k
Activity
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
Replies
2
Boosts
0
Views
1.4k
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
1.1k
Activity
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()     } }
Replies
5
Boosts
0
Views
5.4k
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
1k
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.6k
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
1.1k
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.4k
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.9k
Activity
Oct ’22