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.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
My architecture is as follows:
We create a singleton BusinessLogic instance which contains several categories, represented by classes defined in extensions.
class BusinessLogic {
static let shared = BusinessLogic()
private(set) var foo: FooCategory = FooCategory()
}
In a different file we define the category.
extension BusinessLogic {
class FooCategory {
var hasNewItems: Bool = false
}
}
In reality the class is much bigger, but these are the relevant parts.
From my view controllers I access the properties like
BusinessLogic.shared.foo.hasNewItems
This is done throughout the app, and usually works without problems. In this example though, we access the hasNewItems property on viewDidLoad of our UITabBarController, which sometimes leads to crashes. This is unexplainable to me.
Does anyone have an idea what might lead to the crash? We access the BusinessLogic class even on appStart inside the AppDelegate, where everything works fine.
It seems like one property was in fact nil (as #Rishabh suggested). I don't think posting the whole solution is of any use for you, since it's very specific to my app.
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 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.
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.
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;
}