Post

Replies

Boosts

Views

Activity

Reply to what's different?
What's different? Here's what's different. If you write: var number: Int = 3 Then the next person to look at this code will have no trouble understanding what it is doing. On the other hand, if you write this: var number: Int { return 3 } then the only people who fully understand it will be swift experts. And today, as Swift is a relatively new language, there is a very good chance that the next person who looks at your code will not be an expert. In fact, you should assume that the next person who tries to understand your code will be a psychopath who knows where you live. So avoid not-syntactically-obvious features unless you have a very good reason to use them! What you should do if you want a variable-like-thing whose value is computed when it is used, is use the slightly more verbose "get" syntax that claude shows at the end of his post, which I think is equivalent (someone correct me if I'm wrong): var number: Int { get { return 3 } } The additional syntax there gives the psychopathic future reader a clue what is going on - return 3 is a statement executed in the getter for this not-a-normal-variable thing - so they should have deciphered what your code does before they arrive at your house with their axe.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’22
Reply to Calculate coordinate by distance and heading. How?
Is there any functions in CoreLocation that will allow me to calculate coordinate of the point by heading and distance? No. The only bit of spherical geometry that Core Location has is a method to report the distance between two points: https://developer.apple.com/documentation/corelocation/cllocation/1423689-distancefromlocation There are various difficulties with what you want to do. Firstly, the earth is not flat. But if you're only comparing points that are nearby and you don't need a very accurate answer and you're not worried about corner-cases like the poles or the middle of the Pacific, then you can use an approximation that pretends that the earth is flat. (See Jineshsethia's comment: "a distance on the coordinate plane..." - the earth is not a plane!) Secondly, the earth isn't even a sphere. But if you don't need super-accurate answers then you can ignore that (the error is probably less than 1 %). Distance and bearing between two points on a sphere is something you could probably implement from equations on Wikipedia if you can manage "high school maths". (I think this is what the Stack Overflow posts that you linked to are all doing.) If you actually want the "right" answer, you need the more complicated maths to work with the "squashed sphere" that better approximates the shape of the earth. My recommendation is to use GeographicLib. https://geographiclib.sourceforge.io It seems to be high-quality, and I use it in my mapping apps. It does much more than you need, though. What you need is its functions for "geodesics". See this page: https://geographiclib.sourceforge.io/C++/doc/classGeographicLib_1_1Geodesic.html and scroll down to the example, which I have copied in part below: Geodesic geod(Constants::WGS84_a(), Constants::WGS84_f()); // Alternatively: const Geodesic& geod = Geodesic::WGS84(); { // Sample direct calculation, travelling about NE from JFK double lat1 = 40.6, lon1 = -73.8, s12 = 5.5e6, azi1 = 51; double lat2, lon2; geod.Direct(lat1, lon1, azi1, s12, lat2, lon2); cout << lat2 << " " << lon2 << "\n"; } { // Sample inverse calculation, JFK to LHR double lat1 = 40.6, lon1 = -73.8, // JFK Airport lat2 = 51.6, lon2 = -0.5; // LHR Airport double s12; geod.Inverse(lat1, lon1, lat2, lon2, s12); cout << s12 << "\n"; }
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’22
Reply to Any way to implement a lock in Metal Shader Language?
atomic_compare....() returns true if the location was 0 and has been updated to 1. Your atomic_store...() stores 0. Why do you have the ! in bool test = !atomic_compare...()? (A better name than "test" would help.) Maybe I'm missing something, but I think you want: expected = 0; // We hope it is unlocked bool succeeded_in_locking = atomic_compare_exchange....(flag, &expected, 1, ....); // Try to lock by storing a 1 in place of the 0. if (succeeded_in_locking) { // OK, we have the lock this is where we would do the work protected by it. // Now we want to unlock. // Just write 0: atomic_store...(flag, 0, ....); } else { // We didn't lock - presumably some other thread has it. // Try again. } Anyway... I'm not convinced that a memory_order_relaxed atomic can be used to implement a lock, as there are no constraints on the ordering of those atomic operations relative to the operations that you are trying to protect. But I know nothing about Metal.
Topic: Graphics & Games SubTopic: General Tags:
Jul ’22
Reply to "Open file error: No such file or directory" upon opening iCloud file
How would I manually create the Documents/ directory? In C, mkdir(path, 0777). In C++, create_directory(path). In objC, [[NSFileManager defaultManager] createDirectoryAtURL: [NSURL urlWithFileSystemRepresentation: path] withIntermediateDirectories: false attributes: @[Some@[Extra]VerboSity]here] error: everyonejustpassesnil_becausewe'vegivenup_bythispoint_butReallyWeShouldDoSomethingToHandleErrors] In Swift, same as objC but with different punctuation. I'm not sure if this is necessary. What does seem to be the case is that if you haven't done anything then the empty directory is not visible in e.g. the Files app. I don't know if this is because the Documents directory doesn't exist, or because it is empty and empty directories are somehow hidden. Quite a few apps put a "readme" file in their iCloud Documents directory to make it appear. That is what I have done, using an NSFileManager method called something like copyFileFromHere: toThere: creatingIntermediateDirectoriesIfNecessary: true. So that would create Documents/ if necessary. I don't know what a coordinated write block is You need to look at the documentation for NSFilePresenter, NSFileCoordinator, and UIDocument. These are required for iCloud files, and also for local files if they are accessible from other apps, including the Files app. Basically if you're going to read from a file, you need to do a "coordinated read" so that e.g. an instance of your app on another device or the Files app on the same device are told to save the file first. Coordinated writes are the converse. UIDocument simplifies a lot of this. But one important feature of these coordinated things is that they give you a potentially different path to access, in place of the path that you think you want to use. The point is that if there are conflicts between different devices you can have multiple versions of each file. Having said all that - I don't think it would explain fopen(w) returning "no such file or directory". It there a particular naming convention for the container name? I would suggest reverse-dns i.e. com.your-business-name.your-app-name.this-container-name.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’22
Reply to Account deletion. Manual process - getting back to the user.
Contact them at the start of the deletion process and say "we won't contact you at the end of the deletion process, because at the end of the process, we won't have your contact details any more. If you would like confirmation, you may contact us in 14 days; we will not say 'your account has been deleted' but we will say 'who are you?'". An intelligent user will understand this. (P.S. I have no idea what requirements Apple has.)
Topic: App & System Services SubTopic: General Tags:
Jul ’22
Reply to "Open file error: No such file or directory" upon opening iCloud file
My big break thru was realizing the a file's URL (returned from the Swift code) needs to be modified (replace, for example "%20" with " ") before using them as a file name in the fopen() call. You should be using NSURL.getFileSystemRepresentation to do that. I need to figure out why these files are not visible in the Files app.   I don't yet see them being uploaded to my desktops Possibly because of the lack of a coordinated write.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’22
Reply to Maximum Loading times in games/apps
I don't believe that App Review have a limit, but I could be wrong. The question is, how long will your users be prepared to wait? I suggest that you check how quickly other comparable apps start up, and make yours no worse than average. The danger is a pile of 1-star reviews from impatient people. Is there some particular reason why yours is slow? Maybe someone can suggest how to improve it.
Topic: Graphics & Games SubTopic: General Tags:
Jul ’22
Reply to Is there are way we can continue the app in the background for a life-critical application?
Yes, you can get location updates in the background, that's standard. I think they continue to come in at 1 per second but I'm not sure about that. In theory it may get terminated if some foreground app needs all the RAM and your app is using lots, but in practice I don't think that happens often; it may be more likely that your app crashes while it's in the background and the user doesn't notice. I don't know about sockets. That may be more difficult. You may need to use push notifications. But, reading you post something else occurred to me. Are you aware of the terms in the developer agreement regarding safety-critical apps? E.g. section 3.3.13 - "Applications that use Location APIs .... may not be designed or marketed for ... emergency or life-saving purposes" and section 12: "... APPLE SOFTWARE ... NOT SUITABLE FOR USE IN SITUATIONS ... WHERE ERRORS ... COULD LEAD TO DEATH". Is this something that you just ignore? I ask because I sometimes get questions from users who seem to be using my map apps in emergency-services type applications, and I wonder what I should tell them!
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’22
Reply to Data collection and storage policy
Ignore what other apps (Uber) do. Is there a legal requirement that means you cannot offer account deletion? If there is, the "additional information" they need would be, for example, a link to the law that you believe prevents you from offering account deletion, or a formal opinion from a lawyer, etc.
Topic: Privacy & Security SubTopic: General Tags:
Jul ’22