Post

Replies

Boosts

Views

Activity

Reply to How can I make this kind of scroll menu?
This is a very different question, more for CoreLocation area. So, you should close this thread and start a new one. But a quick answer: Just import CoreLocation and use: let loc1 = CLLocation(latitude: 81.108187, longitude: 37.075812) // Or : let loc1 = CLLocation(places[0].lattitude, places[0].longitude) let loc2 = CLLocation(latitude: 31.076187, longitude: 87.000563) // Or : let loc2 = CLLocation(places[1].lattitude, places[1].longitude) let loc3 = CLLocation(latitude: 31.096688, longitude: 26.991312) // Or : let loc3 = CLLocation(places[2].lattitude, places[2].longitude) let dist1_2 = loc2.distance(from: loc1) / 1000 // In km let dist2_3 = loc3.distance(from: loc2) / 1000 // In km print("dist1_2 =", dist1_2, "km") print("dist2_3 =", dist2_3, "km") You will get: dist1_2 = 5953.932994696864 km dist2_3 = 5650.435157084044 km Note: you'd better rename lattitude into latitude
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Double initialized as Decimal returns number with trailing fractional digits
This will work. let formatter = NumberFormatter() formatter.numberStyle = .decimal let x : Double = 0.94 let string = formatter.string(for: x) ?? "?" print("x as string =", string) let num = try Decimal(string, format: .number) print("As decimal =", num) let numPlus10 = num + 10 print("numPlus10 =", numPlus10) // To show it is effectively a number, not a String You get: x as string = 0.94 As decimal = 0.94 numPlus10 = 10.94
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
So, what is wrong exactly ? It looks like : you have not set width horizontal on the CollectionView, through leading and trailing to the safe area. -> Can you show the constraints you have defined for CollectionView For imageCell -> have you defined (in IB Attributes Inspector) the view Content Mode as 'Aspect fit` ? Label is too large, because you have not define horizontal constraints. -> Logically, you should defined a leading to its container (10 for instance) and a trailing of 60 or 80, to make room for iconLabel -> To make sure that text will fit, select a variable font, with minimum size of 0.6 for instance (in Attributes inspector for Label) -> Can you show the constraints you have defined for Label -> Can you show the constraints you have defined for iconLabel
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to XCode Simulator Frozen
May be your app has crashed or is stuck in some part of code. Did you try with a very basic new app, just a single VC with a single TextField and a button that prints a message ? What do you get then. If it works, you should show the code of the other app…
Nov ’21
Reply to repeat loop inside Vstack
I don't understand your code. where is k initialised ? where is it updated ? Could you show the complete real code, properly formatted and tell what is the exact error you get, where ? However, message is explicit, this pattern is forbidden. But you could write something like: struct ContentView: View { var body: some View { VStack { ForEach (0..<2) { Text("Hello \($0)") } } } }
Nov ’21
Reply to Swift switch statement optimization
Yes, it is evaluated in order. See proof here: https://stackoverflow.com/questions/25006955/does-the-order-of-the-cases-in-a-switch-statement-have-an-impact-on-speed-of-exe But IMHO you are looking for optimisations that don't have much impact. Why do you bother ? In addition, compiler optimises such dispatch of cases: https://stackoverflow.com/questions/47089878/does-the-order-of-cases-in-a-switch-statement-affect-performance/47090061
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to How to Access values Outside Task.Resume()?
First you need to understand what's happening. When you call     let task = URLSession.shared.dataTask(with: urlRequest) { [self] you "send" the closure to another thread. And task.resume() will then order executing. But, without waiting (that's the purpose), code in the func has continued and return is executed before task was executed. You have several ways to solve: You assign the result of the return to some var in your class let's assume those var are: var theNameArray, var thePlaceArray, var theLocationArray, var theArraylength // I do not see the need for such a thing Then, remove the return values from the func, func nearBy() { and assign them to the class properties after the catch theNameArray = nameArray // idem for others you could use semaphores you could also use await/async which is made for this. But that requires some code refactoring
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
Can you list me what should I do with the constraints step by step? I thought I did it in my previous post… To be efficient, send a screen shot of the constraints you have defined, inside the cell (for each object inside) and for the collectionView (the collection itself and its cell). I will inspect them. Also, should the cell be at full width or it can stay as it was in previeous storyboard screenshot that I've sent?  It seems that the screenshot is in the preview, it is not the storyboard screenshot of the cell.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
Ok that was the one I was looking at. But it seems to be defined directly in the collection, not in the cell nib. Anyway, this thread is now too long. You should close it on my answer advising to use a collectionview and start a new thread for the cell layout.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to How can I make this kind of scroll menu?
do you mean constraints for cell in collection view? I mean is that in the cell xib, you define its size ; you can also constraint its width. For instance 400. In storyboard, select the collectionView, add new Constraints to set the width for instance to 420.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
This is a very different question, more for CoreLocation area. So, you should close this thread and start a new one. But a quick answer: Just import CoreLocation and use: let loc1 = CLLocation(latitude: 81.108187, longitude: 37.075812) // Or : let loc1 = CLLocation(places[0].lattitude, places[0].longitude) let loc2 = CLLocation(latitude: 31.076187, longitude: 87.000563) // Or : let loc2 = CLLocation(places[1].lattitude, places[1].longitude) let loc3 = CLLocation(latitude: 31.096688, longitude: 26.991312) // Or : let loc3 = CLLocation(places[2].lattitude, places[2].longitude) let dist1_2 = loc2.distance(from: loc1) / 1000 // In km let dist2_3 = loc3.distance(from: loc2) / 1000 // In km print("dist1_2 =", dist1_2, "km") print("dist2_3 =", dist2_3, "km") You will get: dist1_2 = 5953.932994696864 km dist2_3 = 5650.435157084044 km Note: you'd better rename lattitude into latitude
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Double initialized as Decimal returns number with trailing fractional digits
This will work. let formatter = NumberFormatter() formatter.numberStyle = .decimal let x : Double = 0.94 let string = formatter.string(for: x) ?? "?" print("x as string =", string) let num = try Decimal(string, format: .number) print("As decimal =", num) let numPlus10 = num + 10 print("numPlus10 =", numPlus10) // To show it is effectively a number, not a String You get: x as string = 0.94 As decimal = 0.94 numPlus10 = 10.94
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
So, what is wrong exactly ? It looks like : you have not set width horizontal on the CollectionView, through leading and trailing to the safe area. -> Can you show the constraints you have defined for CollectionView For imageCell -> have you defined (in IB Attributes Inspector) the view Content Mode as 'Aspect fit` ? Label is too large, because you have not define horizontal constraints. -> Logically, you should defined a leading to its container (10 for instance) and a trailing of 60 or 80, to make room for iconLabel -> To make sure that text will fit, select a variable font, with minimum size of 0.6 for instance (in Attributes inspector for Label) -> Can you show the constraints you have defined for Label -> Can you show the constraints you have defined for iconLabel
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to XCode Simulator Frozen
May be your app has crashed or is stuck in some part of code. Did you try with a very basic new app, just a single VC with a single TextField and a button that prints a message ? What do you get then. If it works, you should show the code of the other app…
Replies
Boosts
Views
Activity
Nov ’21
Reply to repeat loop inside Vstack
I don't understand your code. where is k initialised ? where is it updated ? Could you show the complete real code, properly formatted and tell what is the exact error you get, where ? However, message is explicit, this pattern is forbidden. But you could write something like: struct ContentView: View { var body: some View { VStack { ForEach (0..<2) { Text("Hello \($0)") } } } }
Replies
Boosts
Views
Activity
Nov ’21
Reply to Swift switch statement optimization
Yes, it is evaluated in order. See proof here: https://stackoverflow.com/questions/25006955/does-the-order-of-the-cases-in-a-switch-statement-have-an-impact-on-speed-of-exe But IMHO you are looking for optimisations that don't have much impact. Why do you bother ? In addition, compiler optimises such dispatch of cases: https://stackoverflow.com/questions/47089878/does-the-order-of-cases-in-a-switch-statement-affect-performance/47090061
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How to Access values Outside Task.Resume()?
First you need to understand what's happening. When you call     let task = URLSession.shared.dataTask(with: urlRequest) { [self] you "send" the closure to another thread. And task.resume() will then order executing. But, without waiting (that's the purpose), code in the func has continued and return is executed before task was executed. You have several ways to solve: You assign the result of the return to some var in your class let's assume those var are: var theNameArray, var thePlaceArray, var theLocationArray, var theArraylength // I do not see the need for such a thing Then, remove the return values from the func, func nearBy() { and assign them to the class properties after the catch theNameArray = nameArray // idem for others you could use semaphores you could also use await/async which is made for this. But that requires some code refactoring
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Failed to recognize core graphic after update Xcode 13.1?
How long did you wait ? It may take some time to update everything. Try again in one hour.
Replies
Boosts
Views
Activity
Nov ’21
Reply to PHPickerViewController causes memory link
You may have a retain cycle. Have a look here to check: h t t p s : / / stablekernel.com/article/how-to-prevent-memory-leaks-in-swift-closures/
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Get Wifi list without leaving my app is it possible?
You cannot do it directly, only the current network SSID. Otherwise, AFAIK, you have to request permission to Apple: https://stackoverflow.com/questions/49525912/how-to-get-available-all-wifi-network-name-listing-in-ios-using-swift
Replies
Boosts
Views
Activity
Nov ’21
Reply to Do child view controllers inherit the frame of their parents?
and the third view controller comes up the same size and position as the MainController. If I understand your question, this has nothing to do with inheritance. It just depends on how you defined the transition: full screen / automatic…
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
Can you list me what should I do with the constraints step by step? I thought I did it in my previous post… To be efficient, send a screen shot of the constraints you have defined, inside the cell (for each object inside) and for the collectionView (the collection itself and its cell). I will inspect them. Also, should the cell be at full width or it can stay as it was in previeous storyboard screenshot that I've sent?  It seems that the screenshot is in the preview, it is not the storyboard screenshot of the cell.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How can I make this kind of scroll menu?
Ok that was the one I was looking at. But it seems to be defined directly in the collection, not in the cell nib. Anyway, this thread is now too long. You should close it on my answer advising to use a collectionview and start a new thread for the cell layout.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Goggle map crashed after drawing more than 1300 markers with custom color
Unfortunately, the message seems very explicit: you have reached a system limit (1300 markers is quite a lot !). You can file a bug report for enhancement request, explaining why it is important to go beyond the present limit.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21