Education

RSS for tag

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

Education Documentation

Posts under Education tag

39 Posts
Sort by:
Post not yet marked as solved
2 Replies
390 Views
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
Posted Last updated
.
Post not yet marked as solved
2 Replies
308 Views
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
Posted
by Palmon8.
Last updated
.
Post marked as solved
5 Replies
568 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()     } }
Posted Last updated
.
Post not yet marked as solved
2 Replies
328 Views
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!
Posted
by simonaM.
Last updated
.
Post not yet marked as solved
1 Replies
619 Views
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
Posted Last updated
.
Post marked as solved
3 Replies
349 Views
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?!
Posted Last updated
.
Post not yet marked as solved
1 Replies
379 Views
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?
Posted
by chefstef.
Last updated
.
Post marked as solved
2 Replies
691 Views
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 { }
Posted Last updated
.
Post not yet marked as solved
0 Replies
369 Views
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.
Posted Last updated
.
Post not yet marked as solved
2 Replies
3.6k Views
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?
Posted Last updated
.
Post not yet marked as solved
2 Replies
1k Views
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?
Posted
by mhanlon99.
Last updated
.
Post not yet marked as solved
8 Replies
7.8k Views
If you grossed over $20,000 (or 200 sales) in sales from Apple you will receive a 1099-K.There are 2 problems with this:1) This will NOT reflect the 30% that Apple has withheld.2) A 1099-K will only be sent for those regions that meet the criteria for Apple issuing a 1099-K. Thus, this won't reflect all of your sales. Note: this is an assumption as I had more sales then this 1099-K reflects. In my case, I only received a 1099-K for US sales (I assume as it doesn't say). As a result, the difference from what the 1099k is reporting and what I actually received is only 12%, not 30%. That is, for example, the 1099-K says that I had$20,000 in sales, but what was actually deposited in my account was $17,600.How did you guys/gals fortunate/unfortunate enough to receive a 1099-K report this on your taxes?Did you, for example, have:a) 1099-K income of $20,000 with a business expense of 30% = $14,000b) Addional non-reported income of ($17,600-$14,000) = $3600Total: $17,600 (amount actually received from Apple sales)-OR-a) 1099-K income of $20,000 with a business expense of 12% = $17,600Thanks for the help with this!
Posted Last updated
.
Post marked as solved
2 Replies
610 Views
when I'm using for each loop(using repeat command) instead of printing 5 items it is printing 10 times, it always doubles my command it is my code NavigationView {             ScrollView {                 ScrollView(.horizontal , showsIndicators: false){                     HStack(spacing: -10){                         ForEach(0..<5) { item in                             NavigationLink(destination: DetailView()) {                                 CardView()                             CardView()
Posted Last updated
.
Post not yet marked as solved
0 Replies
617 Views
I am trying to access Lego Mindstorm EV3 playground. In tutorials online I see that people can search for additional playgrounds to add to their Swift Playgrounds, but in my app, my only option is to enter a subscription URL and I'm unsure how to obtain this. Can anyone help?
Posted
by Klong.
Last updated
.