Post

Replies

Boosts

Views

Activity

Swift string manipulation
I need to do something that seems simple but I can't figure out the right syntax. Given a string, I need to search for the first occurrence of a substring (not a character). If found, I need to create a new string by removing the part of the old string that is before the substring. I can't see how this is done in Swift. There is a "firstIndexOf" function, but it only searches for one character at a time. I also know that there is a "range(of:)" function, but I can't find its documentation, and I don't know what the return type is, or how I would use it. Thanks, Frank
2
0
599
Feb ’22
Xcode won't remember Git credentials
Xcode won't remember my Git credentials if I close and re-open it. It remembers them while Xcode is running, but always asks me again whenever I shut it down and reopen it. My Git repository is hosted with Beanstalk, which is not one of the ones listed in the drop-down list in Xcode. I have saved my credentials with Git on the command line and I'm able to do Git command line operations without re-entering them, but Xcode doesn't seem to recognize this. I'm really getting tired of retyping my password all the time. What else can I do?
0
0
405
Jan ’22
Bluetooth scanning in background without service ID?
Is there any way to scan for Bluetooth advertising messages while in the background if the device doesn't advertise any service IDs? I've been asked to build and app that does this. The device in question is an off-the-shelf medical alert button (my company doesn't make the device and can't alter its firmware). Upon examining it, I find that it does not advertise any service IDs nor does it offer any ability to connect, it works purely by sending advertising packets. I'm told that there are Android apps that can work with this device even while in the background. I checked the iOS bluetooth docs to see if any new scanning capabilities had been recently added, but could not find anything. Thanks, Frank
1
0
606
Dec ’21
Format Decimal as string in Swift?
I'm trying to figure out the right way to format a Decimal number as a currency value in Swift. For example, if the Decimal contains the value 25.1 I'd want this to print as "$25.10". If it had the value 25, I'd want "$25.00". If it happened to contain a value like 25.4575, I'd want to round it off and display "$25.46". There are a confusing amount of functions surrounding Decimals and string formatting. I know I can't just use String(format: "%.2f", value) like I can do with floats and doubles. There appears to be a new FormatStyle property of Decimal, but I can't use that yet because it requires iOS 15. Thanks, Frank
2
0
6.8k
Oct ’21
ARKit with map data?
Hi, I've been asked to estimate a project that would require ARKit, unfortunately I'm new to the technology and need some quick answers as to how it works. The app my customer wants to build would overlay simple graphics at street addresses, as the user pointed their camera at buildings or storefronts. For this to work, I'd need to be able to have the AR view tell me what map locations or street addresses are being seen in the camera view. Is this possible? Thanks, Frank
1
0
741
Oct ’21
SwiftUI dynamic positioning of a subview
Hi, I'm trying to figure out how to manually position a subview within a view using SwiftUI. For example, when the user taps the screen, I want to place a small icon on the screen at the position tapped. I know how to get the coordinates of the tapped location but I don't know how to either place a view there or move an existing view already being shown to that location. In a regular non-SwiftUI app I can set the frame, or set up constraints. I don't know what the best approach is in SwiftUI. Thanks.
1
0
397
Oct ’21
Sign In with Apple - Not getting email address
I'm using Sign In with Apple and requesting both .fullname and .email. The first time I sign in on any given device, the callback to my app has an authorization credential that contains an email address and a fullname, as expected. However, any subsequent login on the same device does not return either the email address or the fullname. All I get is the user ID string. The server I'm working with requires an email address to log in, so I need that email address. Why does it only appear the first time? Frank
1
0
877
Sep ’21
How to create US Central timezone in Swift?
The server I'm working with returns a date/time string that is always expressed in US central time. There is no timezone information in the string itself. In order to parse this string, I need to create a DateFormatter and then assign its timeZone property. I'm having trouble figuring out the right way to do this. I know that the correct string that means US central time is "America/Chicago", but it appears that the TimeZone initializer is looking for an abbreviation, rather than a full string. I don't know what the correct abbreviation is. I don't want to use "CST" or "CDT" since those denote standard or daylight time. I need something that means whatever the current timzeone is in Chicago. In Java, as an example, the Timezone class accepts "America/Chicago" as an initializer and it works whether or not the calendar is on daylight savings time. Thanks, Frank
2
0
1.5k
Aug ’21
async/await in Swift
I happen to have a lot of experience writing a Windows application in c#, where the async/await pattern has been a standard feature for years. I can say from this experience that it's a great way to handle concurrency and I'm really happy that Apple is bringing this to Swift. I'm often critical of language improvements that end up reproducing things you could already do with a different syntax, but in this case it's definitely worth it. If you've never used async/await, it may initially look confusing. It looks like all you're doing is blocking your thread from running until another thread completes, but what really happens is that your thread returns at the point where the await keyword appears, and then resumes later when the result is available. So if your thread is the main thread, which is the most common case, using await doesn't block the main thread. Exactly how the compiler manages to suspend and resume the thread without destroying your local variables, I don't know, but I'm sure they figured out a way that makes sense. Frank
1
1
1.3k
Jun ’21
Issue with barcode scanning in iOS 14
I've got a fairly old app that I first built back in 2014, and have been maintaining over the years. One of the screens in the app uses the camera to scan barcodes. The barcodes we scan are printed on labels, and are in the org.iso.Code128 format. When the app was first developed, I simply set the metadataObjectTypes property of AVCaptureMetadataOutput to all available types. This worked fine. The app scanned our barcodes very quickly with almost no issues. In 2017, we started seeing issues where barcode scanning was becoming slower. I reasoned that having it configured to scan for every possible barcode format might be the issue, so I went in and changed the code to have it scan only for the org.iso.Code128 format. This helped, for a while. Now, we're seeing the problem again in iOS 14 devices. On some devices it is nearly impossible to scan the barcodes. On others, you have to wait 20 or 30 seconds before the barcode is recognized. What could be causing this issue?
1
0
1.3k
Jun ’21
What is NSURLErrorSecureConnectionFailed?
My app has been reporting error code -1200, "NSURLErrorSecureConnectionFailed", on a very small number of end user devices. I cannot reproduce the error. The devices that report this error have ranged from very old iOS 9 devices to modern iOS 14 devices. The documentation says, "An attempt to establish a secure connection failed for reasons that can’t be expressed more specifically." Can anyone elaborate on what kinds of reasons might cause this error? I'm otherwise stuck, with no way to explain this to my customers and no advice for how they might fix it. Thanks, Frank
2
0
3.4k
May ’21
An error occurred uploading to the App Store.
Whenever I try to upload an app from Xcode, I get this error right as the file upload begins: App Store Connect Operation Error An error occurred uploading to the App Store. This is not a transient problem. I have had this issue for months, ever since I started using an M1 Mac Mini for most of my development. The only workaround I've been able to find so far is to use a different Mac to upload my builds. Luckily, I have another one, but I'm getting tired of doing this. Both Macs are running the same version of Mac OS, same version of Xcode, and are on the same Wifi network. I also checked to make sure the network settings are identical. How can I debug this problem?
1
0
734
Mar ’21