IOS Objective C - Error receiving json data from url
Not 100% sure about your implementation of Provincias
but I think your problem is here:
prov.tipoProvincia = [dic objectForKey:@"Provincia"];// -> ok
prov.tipoIdProvincia = [dic objectForKey:@"idProvincia"];// -> try to send int message to convert String to Int
prov.tipoNumActos = [dic objectForKey:@"Actos"]; // -> same here
Your objects in dict are NSString
but you need to cast them to NSInteger
.
What you could do is:
prov.tipoProvincia = [dic objectForKey:@"Provincia"];// -> ok
prov.tipoIdProvincia = [[dic objectForKey:@"idProvincia"] intValue];// -> you get string but Id is a number
prov.tipoNumActos = [[dic objectForKey:@"Actos"] intValue]; // -> same here
How to stop a function during its execution - JavaScript
Stopping a running function is a bit different than what you are actually showing for code, which is an asynchronous operation happening outside of the function that initiated it.
Running functions can only be terminated from within the function and that is done with either a return
statement or by throwing an exception.
return
can be called conditionally so that the function doesn't always exit at the same point. This is often the case with form validation functions - - if something is determined to be invalid, a return
is encountered so that the form is not submitted. If everything is valid, the return
is skipped and the form is submitted.
Here's a simple example with return
:
function foo1(){
console.log("Foo started...");
if(prompt("Type 1 to terminate right now or anything else to continue...") == "1"){
return; // Function will terminate here if this is encountered
}
console.log("Foo ending..."); // This will only be run if something other than 1 was entered
}
foo1();
Early exit from function?
You can just use return
.
function myfunction() {
if(a == 'stop')
return;
}
This will send a return value of undefined
to whatever called the function.
var x = myfunction();
console.log( x ); // console shows undefined
Of course, you can specify a different return value. Whatever value is returned will be logged to the console using the above example.
return false;
return true;
return "some string";
return 12345;
Stop Javascript Function execution from another Function
JavaScript is normally single threaded - meaning that while a function is executed in the browser no other code can run at the same time - including event handlers such as onclick
(they will be triggered only after the function is complete). So, in this case you cannot interrupt the execution of a function from code.
There are two workounds:
The long running function could take breaks intentionally, allowing other code to execute.
//set this to true from an event handler to stop the execution
var cancelled = false;
function longRunningFunction() {
if (cancelled) {
return;
}
// do some work, but not all
// save your progress to be able to resume when called again
if (!done) {
// release control, so that handlers can be called, and continue in 10ms
setTimeout(longRunningFunction, 10);
}
}Use web workers. They allow running code in parallel, but have some restrictions and are not supported by all browsers.
stop executing the loop until the function is completed
Note: Can't test it at the moment, might run into the same problem
Your displayBlocks
method is not awaitable. Have you tried something like
const displayBlocks = async (key) => {
return new Promise((res,rej) => { // return with promise to make it awaitable
setTimeout(() => {
divArray.classList.remove('active');
res('color removed');
}, 500)
});
console.log(key);
ref.current.childNodes[key].classList.add('active');
let result = await promise;
return result;
}
const handleNewGame = () => {
blockArray = []
// generate array with random cells according to points
for (let i = 0;i< props.points;i++) {
let key = Math.floor(Math.random() * (props.board.length)) + 0;
var res = await displayBlocks(key); // await should halt the loop
console.log(res);
blockArray.push(key);
}
console.log(blockArray);
}
Related Topics
Parametrized Unit Tests in Swift
How to Use @Fetchrequest Outside a View
How to Check If a Variable Is Nil
Errors When Update Code to Avoid Deprecation Warnings Withunsafemutablebytes in Swift 5
Module Compiled with Swift X.1 Cannot Be Imported in Swift X.0.2
Nscalendar in Swift - Init Can Return Nil, But Isn't Optional
Editing a Package Dependency as a Local Package
How to Add Two Generic Values in Swift
Swift: Urlsession.Shared.Datatask Says Status Code 304 = 200
Error "[Sharesheet] Connection Invalidated" Error iOS13+ But Not on iOS 11.4
Swift - How to Deal with Uncaught Exception
Nsdatepicker in Nsstatusbar Nssmenuitem Not Receiving Input
Nil Cannot Be Assigned to Type Avcapturedeviceinput
How to Retrieve The Name of Participants in Msconversation
iOS Swift, Aws Cognito User Pool, Unable to Refresh Access Token