Endless function calling loop [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm working on my iOS project again. However, I seem to have hit a cascading eternal loop of function calls of which I don't know why it happens. The GDB output can be viewed here:
http://img205.imageshack.us/img205/527/gdberror.png

dot notation is a syntactic sugar for setter/getter methods.
self.username = x;
is the same as
[self setUsername:x];

self.username uses the setUsername method, hence your issue. Just use:
username = user;

Remove the .self from your code.
When you write self.username you are calling your -(void)setuserName:(NSString*)user function again and again.
it should be
-(void)setUserName:(NSString*)user{
userName = user;
}

Related

How to write a completion block in objective-C? [closed]

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
}];

For Loop Syntax: Create New UIView . . [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm new to iOS, and I want to construct a for loop that says "for every object in my array, create a new UIView". I know this would be considered very basic and simple, but how would I code this?
for (Object *object in Array) {
UIView *view = [[UIView alloc] initWithFrame:???];
// Do whatever else you need here
[??? addSubView:view];
}
I have done "for (Object *object in Array)" in case you need data from said object inside your views subviews.
You want to read the documentation for UICollectionViewController and UITableViewController. They manage collections of subviews for you.

How to fix arrayWithObject cannot be nil warning? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
When running analyze in Xcode I get this warning:
Argument to 'NSArray' method 'arrayWithObject:' cannot be nil
The line of code that it is happening on for me:
if (indexPath) {
indexPath = [self differentPath:indexPath];
}
NSArray *exampleArray = [NSArray arrayWithObject:indexPath];
Which is inside a NSFetchedResultsController delegate method.
How do I fix this warning?
The warning is pretty clearly pointing to the fix: make sure the object cannot be nil. There are two different easy ways to fix this.
First you could make sure you are setting your pointer to a valid object within the same method as the arraryWithObject: call.
Or you could you could wrap your arraryWithObject: call in an if statement that checks that your object isn't nil.

MACRO Function doesn't return an objective C object [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm defining a MACRO function to return me an NSDictionary object. Here is the code that I tried
#define GetDictionary(name,description,imageName) [NSDictionary dictionaryWithObjects:#[name,description,imageName] forKeys:#[ATTRIBUTE_TITLE,ATTRIBUTE_DESCRIPTION,ATTRIBUTE_IMAGE_NAME]]
#define GetDictionary(name,description,imageName) #{ATTRIBUTE_TITLE:name,ATTRIBUTE_DESCRIPTION:description,ATTRIBUTE_IMAGE_NAME:imageName}
But evety time I try to call this method to get a dictionary object, the compiler gives an error "collection element of type void * is not an objective c object". Immediate help will be appreciated.
First, if all possible, avoid these kinds of macros. They tend to cause exactly these kinds of headaches. I assume you have further macros for ATTRIBUTE_TITLE, etc. I highly recommend using simple functions rather than macros. You'll get much easier-to-understand code. There is seldom a reason to use macros this way.
My first suspicion is that ATTRIBUTE_TITLE (or one of the related macros) is not a proper object. Most likely you've done something like:
#define ATTRIBUTE_TITLE "foo"
rather than
#define ATTRIBUTE_TITLE #"foo"
Though the void* complaint is interesting… Anyway, switching this to a function, and changing ATTRIBUTE_* to constants rather than macros, will likely make the error obvious.

How do I post comment in dark background [closed]

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)

Resources