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.
}];
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have created utility class for UIAlerts. I am using blocks
My code, that user should create, looks like this:
MyAlertMessage * a = [[MyAlertMessage alloc] initWithTitle:#"Hello" WithMessage:#"World"];
[a addButton:BUTTON_OK WithTitle:#"OK" WithAction:^(void *action) {
NSLog(#"Button OK at index 0 click");
}];
[a addButton:BUTTON_CANCEL WithTitle:#"Cancel" WithAction:^(void *action) {
NSLog(#"Button Cancel at index 1 click");
}];
[a show]
Full class can be seen here: https://github.com/MartinPerry/UIAlert
Now, If I do this, after [a show] ARC destroys my class, so blocks are no longer working and gives me error. I have solved this by creating singleton class that holds reference to created MyAlertMessage (message ads and destroys itself from this manager). Is this the correct solution or it should be done better, without this singleton manager?
Manager and appropriate class can be found here: https://github.com/MartinPerry/UIAlert/blob/master/UIAlert/MyAlertMessage.m
The example code you posted uses a local variable to create a MyAlertMessage object. Since it is a local variable, it goes out of scope as soon as execution leaves the current set of braces (method, if statement, whatever.) As soon as that happens nobody has a strong reference to the object, so it gets deallocated.
Make the MyAlertMessage variable an instance variable and set it to nil when you are done with it.
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
}];
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
When I create a new file in Xcode I can specify a subclass of my new class. But when it is already created, how can I know which subclass has it?
Thanks.
You see that in the class definition / .h file, for example:
#interface BCFrequencyPlot : NSView
BCFrequencyPlot is a subclass of NSView.
During compilation, you can type:
po [self class]
It will show you class of self. You can check class for any object currently in scope.
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/