Post

Replies

Boosts

Views

Activity

How to catch the dreaded "uncaught exception"?
I'm working on an engineering app that uses a bunch of java code I succefully converted using J2OBJC. Amazing! I can call the functions defined in that java code from my Swift code and it works nicely most of the time.But that java code throws an "OutOfRangeException" whenever the user input paramaters fall out of some range. The error ends up in my AppDelegate and crashes my app there.Is there a way to catch this "exception" gracefully without crashing?I've tried the following but it doesn't work, as Xcode warns:do { 'catch' block is unreachable because no errors are thrown in 'do' block let myVar = JavaProject().someFunction(with: Temp) } catch { }*** Terminating app due to uncaught exception 'OutOfRangeException', reason: 'JavaProject.OutOfRangeException'
5
0
2.6k
Apr ’20
Unexpected dictionary behavior
A "normal" for..in loop on an array handles the elements in the order you would expect. But not this one.Go ahead and try this in a playground. Every time it runs, I get a different ordering of the keys and never get back 1,2,3,4,5 as entered. If I make another loop around the loop shown (as commented out), it'll give the same key order for each iteration. But a different key order appears when the whole thing is rerun.Confused.import UIKit let dataTable: [String: [Double]] = [ "1Cat": [99.95, 0, 0.05, 0, 0, 0, 0.04], "2Dog": [1, 1, 0, 98, 0, 0, 0.2], "3Mouse": [49.0, 43.2, 3.9, 0, 0.2, 3.7, 0.05], "4Gerbil": [40.3, 55.4, 3.0, 0, 0.4, 0.9, 0.05], "5Fish": [7.7, 90.8, 1.2, 0, 0.1, 0.2, 0.05]] for i in dataTable { print(i) } // for j in 1...4 { // for i in dataTable { // print(i) // } // print("\n") // }
8
0
1.1k
Mar ’20
Swift Project including both C and C++
I'm familiar only with Swift. I have a running Swift app that I want to add other code to, from projects I've found online. One project was in C and with just a few hoops to jump, I got that part working. Yay me.Now I'm trying to add some C++ code and I'm hitting roadblocks.First question: Is my current Objective C Bridging Header the only one I need, or do I need another bridging header?Second question.The problem I'm having is with this code in my bridging header:#include "IF97.h" // The project I want to use #include <cmath> #include <vector> #include <algorithm> #include <iostream> #include <iomanip> #include <stdexcept> #include <stdio.h>All but the first and final lines produce "file not found" errors.
15
0
9.0k
Mar ’20
Domain=HMErrorDomain Code=80 "Missing entitlement for API."
A similar discussion here:https://forums.developer.apple.com/message/73484#73484I'm controlling an Ecobee 3 thermostat and a couple of switched outlets with my app (called AirCompare and in the store) using HomeKit. It works well and I've been running it continuously for over a year. The thermostat responds more slowly than the switches and sporadically I get the rare error shown in the title. The user sees only a red dot indicating an error but the text of the error prints to my log file. The error can usually be cleared by the user by taking any of a number of actions in the app that will call the Home Manager again.I thought this occasional error might have something to do with the thermostat's slow response causing something to time out, but the text of the error suggests someting else is screwy.I'm lost as to where to begin. I'd like to make this error even more rare. I'm thinking of adding another call of HM if the error is produced but this feels kludgy and I'd have to protect against an endless loop if the error persisted.
4
0
3.0k
May ’19
How to check for Main thread from the background?
I have a background operation (a web fetch) that grabs some data from the internet. I need to dispatch out that data as soon as possible during the fetch and have been using the following: func dispatchWebData(myNumber: Double) { if UIApplication.shared.applicationState == .active { DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { self.myFunction(myNumber: myNumber) } } else { DispatchQueue.global(qos: .userInteractive).asyncAfter(deadline: .now() + 0.2) { self.myFunction(myNumber: myNumber) } } }If the app is active, data handling is dispatched to the Main thread and the UI gets updated as soon as the data is available. If the app is not active, the main thread is not available so I dispatched data handling to the global thread. This was/is working fine.Now the MainThread Checker is sending me the little purple square warning that "UIApplication.applicationState must be used from main thread only".First, it seems silly that you can't check the application state from the background. What's the point if you can only check the state while the state is Active?But I wouldn't care about that issue as long as I can get my data handling to move forward. So I'm wondering is if I can check for the existence of the main thread and then dispatch to it if it's there, otherwise to the global thread. Other ideas welcome.
13
0
16k
Mar ’18
error: failed to launch app -- iPhone has denied the launch request.
I was working on my app in Xcode and, after making some changes in Interface Builder and installing to my iPhone, this error popped up:error: failed to launch '/private/var/containers/Bundle/Application/long number/MyApp.app' -- X’s iPhone6 has denied the launch request. (Where X is me).I've tried:Quitting and relaunching XcodePowering down and restarting the iPhoneInstalling the latest Xcode beta 9.1 Beta 9B46Toggling the checkmark for "Automatically manage signing"Using Simulator (which works) I've found reference to this error elsewhere and some people had success by paying attention to their signing. I'm signing as an iOS Developer, so I don't know what else to do.
17
0
19k
Oct ’17
Why can't I edit the iTunes Connect user roles?
My first app and my first experience with iTunes Connect. I can add and delete users, and assign their roles when I add them, but I cannot edit them once added. The only thing I can do is "Resend Invitation".I'm logged in as myself with the Admin/Legal role. I have assigned all my other users the "Developer" role. The only Apple ID that is not greyed out in my list of users is my own. If I double-click my own AppleID to edit my roles, I can see that every checkbox is selected.https://help.apple.com/itunes-connect/developer/#/deva097c6c29I've read the above, but it mentions just double-clicking the user's AppleID in order to edit that user's roles an app access. But I can't do that.What am I missing?
6
0
13k
Jul ’17