Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm having trouble creating completion blocks. I found the solution here
. It works for me, but I don't quite understand this. Now I'm still confused and don't know how to write a block myself. Are there any batter ways to understand blocks? Also, when should I use it? Is there anything that can replace blocks?
Should I create it as a property? Method perimeter? Do they have difference in efficiency?
Thank you!
check out http://fuckingblocksyntax.com for syntax.
For personal choice I like to return value and error in the completion block (similar to iOS framework pattern)
As an example;
declaration
- (void)fetchStuff:(void (^)(id value,NSError *error))completion;
calling the function
// async fetch
[object fetchStuff:^(id value, NSError *error) {
// do stuff with value
}];
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Using a singleton object in a block will create a strong reference cycle in the code ?
As I have more then 5 singleton object in application.
You have to use weak reference of singleton inside blocks.
YourSingleton *singletonInstance = ---- //get your singleton instance here
typeof(YourSingleton) __weak weakSingletonInstance = singletonInstance;
// your block
^
{
// Now use weakSingletonInstance inside the block.
}];
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hai I am new to xcode My code is below,
-(void)XYZ:(NSString *)id1 {
int id2 = [id1 intValue];
NSLog(#"%d",id2);
}
I need to use the id2 value in another class like below,
-(NSArray *)Vehicles {
NSString *urlString=[NSString stringWithFormat:#"http://www.xxxxxx.com/xxx_webservice/vehiclelist.php?uid=%d&format=json",id2];
}
Please guide me to pass the value thanks in advance...
First, you should read some docs about objective-c and OOP.
What you are calling classes, are methods. And if you want to pass one variable to a method, you have to declare it in the method declaration:
-(NSArray *)Vehicles:(NSInteger) id2 {
NSString *urlString=[NSString stringWithFormat:#"http://www.tranzlogix.com/tranzlogix_webservice/vehiclelist.php?uid=%d&format=json",id2];
}
And you have to pass it when you call it, if you are calling the method from your class, a correct way will be: [self Vehicles:id2]
But i suggest you to read a lot before asking so basic questions.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm using blocks inside a NSOperation. The main method of my NSOperation looks like this:
- (void) main {
[self callMethodOfALiraryUsingCompletionBlock:^() {
//this method takes time to execute, will call this block when done
}];
}
I'd like my NSOperationto terminate when what's inside the block is done. Currently, it returns directly, before what's inside the block is executed ... Any idea how I can solve this ?
Little detail in your question, here is one possible outline which may help:
Create a semaphore (dispatch_semaphore_create)
Execute your library code asynchronously (dispatch_async)
Have the completion block for your library code signal the semaphore
Have your main method wait on the semaphore
HTH
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Call me crazy...
Hey i wanna know that how you people comment or ask your question in dark background. I am new at this site so tried searching the FAQs but couldn't find the answer. How do you write your code related thing in different background and general sentences in simple background?
**Its a Check and it works.**
Do you mean
like this because this is a blockquote and you can use either a > prefix or highlight and click the speech marks
the other is a bit like this and that is a back tick ` which denotes a code block or you can highlight code like this
namespace SomeNameSpace
{
public class SomeClass
{
public int foo()
{
return 1+1;
}
}
}
Which does a similar thing and you do that by highlighting a block and clicking the {} button or you can indent from the beginning by 4 which buts it into that mode.
There are formatting hints in the editor (the orange question mark)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
hey i'm new to iOS and having a hard time with RestKit
can anyone help me on how to do these two post requests
1)post a long value and map the response to
#interface CountResultVO : NSObject
{
long offercount;
long insertCount;
long favouriteOfferCount;
long favouriteInsertCount;
}
2)post the above object and map response to
#interface FooList : NSObject
{
NSArray * foo;
}
my main problem is posting payloads of primitive variables like int, long etc instead of mapped objects.
this may be useful to you: http://liebke.github.com/restkit-github-client-example/