Post

Replies

Boosts

Views

Activity

Reply to What is wrong in this
What is wrong in this First, the formatting… 😉 var aNumber = Int(readLine()!)! func dayOfTheWeek(day: Int) { switch dayOfTheWeek { case 2: print("Monday") case 3: print("Tuesday") case 4: print("Wednesday") case 5: print("Thursday") case 6: print("Friday") case 7: print("Saturday") case 8: print("Sunday") default: print("Error") } } dayOfTheWeek(day: <#Int#>) This code is not very robust. Unwrapping without checking for nil may cause crashes. For instance, you'd better write: var aNumber = Int(readLine() ?? "0") ?? 0 You cannot use the func name in the switch, in addition it would be a wrongType (a func () -> Void, and not an Int for the switch) Does your week really starts at 2 ? It is probably 0 (maybe 1) ; in anglo saxon world, first day is sunday (0) So, at the end your code should look like this: var aNumber = Int(readLine() ?? "0") ?? 10 func dayOfTheWeek(day: Int) { switch day { case 1: // if first day is 1 ; print("Monday") case 2: print("Tuesday") case 3: print("Wednesday") case 4: print("Thursday") case 5: print("Friday") case 6: print("Saturday") case 7: print("Sunday") default: print("Error") } } print(dayOfTheWeek(day: aNumber))
Dec ’21
Reply to How to set timer to go to next view controller
You asked a very similar question in another thread (and did not tell if the solution proposed worked). So it is a similar solution here: use DispatchQueue.main.asyncAfter let delay : Double = 5.0 // 5 seconds here DispatchQueue.main.asyncAfter(deadline: .now() + delay) { // Code to go to other controller, either segue, or VC instantiation }
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’21
Reply to UICollectionViewCell improperly sizes itself after calling reloadData()
collectionViewCells stack on top of each other A probable reason is that your cellForItemAt causes the problem.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { For instance, if you add subviews in cell, you have to remove first any existing subview in the cell and add new ones. So, please show the code of the func to confirm.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’21
Reply to I need basic help.
Do you want to learn ? Then forum can help you if you expose what you are not able to do yet. If you want to share idea, and get some advice on how to do it, please expose the idea. On the other end, if you want to sell an idea, then the forum is not the right place, this type of soliciting has no place here. Please explain and eventually detail the idea.
Topic: App & System Services SubTopic: General Tags:
Dec ’21
Reply to Change view controller automatically doesn't work
it doesn't work That does not provide any useful information. What do you get Do you get error message? Do you get a crash ? what do you expect ? Is it SwiftUI ? If so, show complete code I tested in a project, it works as expected. Are you sure you defined IDKview class in IB correctly ? And please, answer the post here, not in a new one, and close previous posts if they are terminated.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’21
Reply to Cancel URLSession.shared.dataTask
Where is self.state defined ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to How to set timer to show text after certain period of time on screen
You can use asyncAfter to display labelToShow (UILabel) which was initially hidden (in IB or at viewDidLoad) To wait for 2 seconds: DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { labelToShow.isHidden = false } You could also flash it with some animation, to make sure user will notice…
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to What is wrong in this
What is wrong in this First, the formatting… 😉 var aNumber = Int(readLine()!)! func dayOfTheWeek(day: Int) { switch dayOfTheWeek { case 2: print("Monday") case 3: print("Tuesday") case 4: print("Wednesday") case 5: print("Thursday") case 6: print("Friday") case 7: print("Saturday") case 8: print("Sunday") default: print("Error") } } dayOfTheWeek(day: <#Int#>) This code is not very robust. Unwrapping without checking for nil may cause crashes. For instance, you'd better write: var aNumber = Int(readLine() ?? "0") ?? 0 You cannot use the func name in the switch, in addition it would be a wrongType (a func () -> Void, and not an Int for the switch) Does your week really starts at 2 ? It is probably 0 (maybe 1) ; in anglo saxon world, first day is sunday (0) So, at the end your code should look like this: var aNumber = Int(readLine() ?? "0") ?? 10 func dayOfTheWeek(day: Int) { switch day { case 1: // if first day is 1 ; print("Monday") case 2: print("Tuesday") case 3: print("Wednesday") case 4: print("Thursday") case 5: print("Friday") case 6: print("Saturday") case 7: print("Sunday") default: print("Error") } } print(dayOfTheWeek(day: aNumber))
Replies
Boosts
Views
Activity
Dec ’21
Reply to Allowing user input in SwiftUI Alert
There is detailed answer here to overcome SwiftUI limits. Maybe that's what you did. https://stackoverflow.com/questions/56726663/how-to-add-a-textfield-to-alert-in-swiftui You could file a bug report for enhancement.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to I can't update macOS Monterey on my macbook pro
Did you try to download from here: https://developer.apple.com/download/release/
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Allowing user input in SwiftUI Alert
The right place to make such a request is Feedback Assistant: https://feedbackassistant.apple.com
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to How to set timer to go to next view controller
You asked a very similar question in another thread (and did not tell if the solution proposed worked). So it is a similar solution here: use DispatchQueue.main.asyncAfter let delay : Double = 5.0 // 5 seconds here DispatchQueue.main.asyncAfter(deadline: .now() + delay) { // Code to go to other controller, either segue, or VC instantiation }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to UICollectionViewCell improperly sizes itself after calling reloadData()
collectionViewCells stack on top of each other A probable reason is that your cellForItemAt causes the problem.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { For instance, if you add subviews in cell, you have to remove first any existing subview in the cell and add new ones. So, please show the code of the func to confirm.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to I need basic help.
Do you want to learn ? Then forum can help you if you expose what you are not able to do yet. If you want to share idea, and get some advice on how to do it, please expose the idea. On the other end, if you want to sell an idea, then the forum is not the right place, this type of soliciting has no place here. Please explain and eventually detail the idea.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Change view controller automatically doesn't work
You should answer the other post ; better than creating a new one for the same question.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Change view controller automatically doesn't work
it doesn't work That does not provide any useful information. What do you get Do you get error message? Do you get a crash ? what do you expect ? Is it SwiftUI ? If so, show complete code I tested in a project, it works as expected. Are you sure you defined IDKview class in IB correctly ? And please, answer the post here, not in a new one, and close previous posts if they are terminated.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to How to set timer to go to next view controller
How do I tell from which to which view controller should it go As I said, you can instantiate the VC (as you did in another post) or you can perform segue that you can define in IB.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Change view controller automatically doesn't work
It seems your answers to some posts are not visible yet. And don't forget to close the threads, that makes it much easier to understand it is solved.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to iOS Safari web extension works only in simulator
What is the extension about ? Have you checked if some privacy setting on the phone could block the extension ?
Topic: Safari & Web SubTopic: General Tags:
Replies
Boosts
Views
Activity
Dec ’21