bool for key in NSMutableArray |
Use index instead of key for an array.
NSDictionary dictionary = (NSDictionary *)dataArray[0];
if ([(NSNumber *)[dictionary objectForKey:@"success"] boolValue]) {
// ...
}
|
Deep copy of an NSMutableArray of custom objects with NSMutableArray members |
In order to deep copy the content of the array
[[NSMutableArray alloc] initWithArray:srcArray copyItems:YES];
will send copyWithZone: to every object inside the collection. If they
don't respond to this selector, you'll get a crash.
Have your CustomParent class to conform to the NSCopying protocol and
you're done.
Here's some extra info on how do achieve it: Implementing NSCopying
|
Using a strong enum (C++11) of type bool fails for template bool argument, why? |
Strongly typed enums mean that you can only, implicitly, compare and assign
values in the same enum class. The solution is to use a non-strongly typed
enum example:
enum test : bool
{
yes,
no
};
bool x = test::yes; // ok
Or as suggested by Tom Knapen: explicitly cast the enum
enum class test : bool
{
yes,
no
};
bool x = static_cast<bool>(test::yes); // ok
|
bool _WebTryThreadLock(bool), 0xa871560: Multiple locks on web thread not allowed! Please file a bug. Crashing now |
There was table which i was reloading and error was coming. The tableView
reloadData command is also not thread-safe.
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
|
Declaration Syntax Error for a function bool f(bool* b) in Borland C++ |
Put this at the top of your source file. If it works after that, then
Borland c++ simply doesn't support bool type. If not, I have no clue why
you get Syntax error.
typdef byte bool;
#define true 1
#define false 0
|
conversion from NSMutableArray of NSData to NSMutableArray of NSString? |
I am not aware of anyway besides visiting each element, like:
NSMutableArray *mutableArray; // your array of objects
for (int i = 0; i < [mutableArray count]; i++)
mutableArray[i] = [[NSString alloc] initWithData:mutableArray[i]
encoding:NSUTF8StringEncoding];
|
(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI is never called |
Facebook developer site they are suggesting, you have to start the section
when applicationDidFinishLaunching itself. So you need to call
openSessionWithAllowLoginUI: NO (no need to provide the login ui) from
there. Dont worry if the user is not logged in this method wont do
anything. In other case if the user is already authorized it will start a
session for the user and change the state also(you will get notified) so
you can set the login button accordingly. Finally wether this method failed
to start a session allow the user to login through login button by calling
openSessionWithAllowLoginUI: YES
|
Why do bool.TrueString and bool.FalseString exist? |
In easy words. Boolean is a Structure. this boolean expose ToString()
method which represent a human readable text for the users. So if you write
some thing like.
bool b = false;
b.ToString();
the output will be the "False" insteed of 0. the "False" is readable by
human and easyly being captured.
Also some where you may want to parse a text value to a boolean value. so
these also can be represented as boolean values. for example. we use
Boolean.TryParse("false" ,out mybool)
the false value is being set by the Tryparse method as this finds that we
can read values from strings tool.
|
How do I idiomatically convert a BOOL to a bool? |
There's no need for any explicit conversion:
BOOL x = some_value;
bool b = x;
The implicit conversion of a numeric type to bool yields false for a value
of 0, and true for any non-zero value.
Incidentally, you've told us how <windows.h> defines FALSE and TRUE.
How does it define BOOL? (From your comment, it's typedef int BOOL;)
But some compilers may warn about this implicit conversion, even though
it's perfectly valid code. Compilers are free to warn about anything they
like, including the ugly font you used to write your code. g++, for
example, doesn't complain about the conversion, even with:
g++ -std=c++11 -pedantic -Wall -Wextra ...
But according to this online Visual C++ compiler, VC++ does produce a
warning:
warning C4800: 'BOOL' : forcing value to bool 'true' or 'fal
|
27 different Bool to Bool values in Haskell |
There are three values of type Bool: True, False and bottom (expressions
for which the evaluation doesn't finish or expressions for which the
evaluation turns into errors).
Then, there are an exponential number of functions from A to B. More
exactly |B| ^ |A|.
Thus, there are 3^3 = 27 functions of type Bool -> Bool.
Now, for the second part of the question: function starting from bottom can
be only 2: the one constantly returning True and the one constantly
returning False. Then you have to add the number of functions from {True,
False} to {True, False, bottom} which is 3^2. So, in total you'll have
9+2=11 functions.
Edit: Here are the 11 possible functions:
B is bottom, T is True, F is False. The last row represents the const True
and the const False functions while the first th
|
Convert Func to Func |
Why not pass it in
public Cv3AddressDao
ReadSingle<TEntity>(Expression<Func<TEntity, bool>>
predicate)
{
// ...
}
...
var dao = new MyDao();
var addr = dao.ReadSingle<MyEntity>(x => x.SiteId == 1);
|
why does a constant string become a bool when used for input to variant? |
As someone's comments state, the missing are headers which I missed
removing the references (they exist here) to, but I had removed the usage
of.
However, the actual problem above is with C++ basic object conversion
rules. In case soemone else runs into this:
c provides a direct conversion from a pointer type to a boolean.
c++ adds a std::string class. That class provides a constructor from const
char*.
Direct conversions are simpler than class constructors, thus that
conversion is preferred when either can be used. Because it is simpler, it
is also not considered ambiguous over which conversion to use. Thus,
though char* to string is what was intended, the compiler did pointer to
boolean, causing the output to be a boolean.
The information was given by VeXocide on the freenode ##
|
Xcode Add NSMutableArray to a NSMutableArray |
The problem is that you shouldn't be using removeAllObjects as it just
cleans the array out (deleting the work you just did). Instead, you should
be creating a new array (tempImageArray = [NSMutableArray array];).
|
Getting from Func + T instance to Expression> |
T instance = GetSomeT();
Predicate<T> MyPredicate = x => comparer(x, instance);
TRepository.GetAll().Where(MyPredicate);
Taking in account the comment gave below, here is how you make a
Expression<Func<T, bool>>
T instance = GetSomeT();
Expression<Func<T, bool>> Exp = x => comparer(x, instance);
TRepository.GetAll().Where(Exp);
That's exactly the same, just with different var type.
In short you can just:
TRepository.GetAll().Where(x => comparer(x, instance));
|
Convert Expression> to Expression> |
Why don't you just change your method to be:
T GetSingle(IRepository<T> repository, Expression<Func<TSource,
Boolean>> predicate)
{
return repository.GetAll().Single(predicate);
}
so instead of this:
GetSingle(myRepository, (a,b) => a.Id == b.Id, myEntity);
you should be able to do this:
GetSingle(myRepository, a => a.Id == myEntity.Id);
|
How to add sum of NSMutableArray |
This is because you keep re-creating your "scoreTally" array so it's
constantly being reset to an array with a single NSNumber object.
You need to create your "scoreTally" array once and then add additional
objects to it as scores keep getting added.
So I'd recommend moving your "scoreTally" creation somewhere else, for
example the "viewDidLoad" method of your view controller (making sure to
keep "scoreTally" around via an ivar or a property).
|
Min and Max Value of an NSMutableArray |
You can get maximum and minimum number as below code. It may help you
NSNumber * max = [array2 valueForKeyPath:@"@max.intValue"];
NSNumber * min = [array2 valueForKeyPath:@"@min.intValue"];
NSUInteger numberIndex1 = [array indexOfObject:min];
NSUInteger numberIndex2 = [array indexOfObject:max];
NSLog(@"Max Value = %d and index = %d",[max intValue],numberIndex1);
NSLog(@"Min Value = %d and index = %d",[min intValue],numberIndex2);
|
ios compare two NSMutableArray |
Jason, I am not pretty sure about what your requirements are but as per I
understand predicate is answer for your question, which are very helpful
for searching. Block predicates have made it very easy to use.
NSArray *allFbIds = [self.myPersonArray valueForKeyPath:@"UserDef2"];
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id
evaluatedObject, NSDictionary *bindings) {
NSDictionary *data = (NSDictionary *)evaluatedObject;
NSString *fbid = [data objectForKey:@"id"];
return [allFbIds containsObject:fbid];
}];
NSArray *filetr = [array filteredArrayUsingPredicate:predicate];
If any of fbID will be available in property UserDef2 in KP_PERSON object
of myPersonArray that will be in the filtered in the array.
I think this might solve your problem.
|
NSMutableArray add the last object only |
Try something like this:
- (NSMutableArray*) getFairInfoArray: (NSString*) FairIdForThisMethod From:
(NSMutableArray*) exibitorsForThisMethod
{
NSMutableArray* exibitorsWithFairId = [[NSMutableArray alloc] init];
for (ExibitorInfo* currentExibitors1 in exibitorsForThisMethod)
{
if ([currentExibitors1.FairId isEqualToString:
FairIdForThisMethod])
{
ExibitorInfo* currentExibitors2 = [[ExibitorInfo alloc] init];
[currentExibitors2
setExibitorName:currentExibitors1.exibitorName];
[currentExibitors2
setStallLocation:currentExibitors1.stallLocation];
[currentExibitors2
setExibitorCellBackGround:currentExibitors1.exibitorCellBackGround];
[currentExibitors2
setCompanyLogoURL:currentExibitors1.companyLogoURL];
|
NSMutableArray's objects are same |
It is probably because you are using backlist.count-1 as your index instead
of using i.
try this:
while (i!=backlist.count) {
NSLog(@"%@ %@",[[backlist objectAtIndex:i] objectForKey:@"id"
],[[backlist objectAtIndex:i] objectForKey:@"name" ]);i++;
}
|
NSMutableArray Resetting Itself? |
There are good clues in your log output. There are multiple instances of
the view controller (see the different values for 'self'?). They each have
their own array. See this code...
-(IBAction)newFileMenubar:(id)sender{
[newFileWindowControllerArray addObject:[[NewFileWindowController
alloc]initWithWindowNibName:@"NewFileWindowController"]];
When you press the button associated with that action, your app builds
another view controller and places it in the array. That view controller
gets the awake from nib message and allocates another array, and so on.
To confirm this, change the code as follows:
-(IBAction)newFileMenubar:(id)sender{
[newFileWindowControllerArray addObject:@"Hello world"];
// and comment this out, for now:
// [[newFileWindowControllerArra
|
NSMutableArray not showing first value |
The picker cannot show a random object, but a only a string (in its base
configuration). Make sure you add the name or some other string attribute
of your Products class to the array, (or instruct your picker's datasource
to use the right field).
You should really change some names of your classes and variables. If one
instance of your class represents a product, the class name should be
Product not Products. Also, to use a property name like all is really not
intuitive - try to think of something more generic and descriptive.
Also, in your for loop you set i to 0, use it once and then increase it at
the end of the loop. Why? Your index set code can also be eliminated.
|
NSMutableArray behaviour with ARC |
If it's a copy then no. If you've added it as a reference then yes. It's
just a pointer to an object so any changes to your object will apply to the
object reference in the array.
Don't be confused by the NSMutable part of the array. The same thing
happens with a normal NSArray: if you change the object, then the array
will have a reference to the changed object. The mutable part only applies
to the array, not the objects in the array.
|
IOS: save an NSMutableArray |
You should read :
https://developer.apple.com/library/mac/#documentation/cocoa/reference/foundation/Protocols/NSCoding_Protocol/Reference/Reference.html
You need to implement initWithCoder and encodeWithCoder.
To save to file, just do :
[NSKeyedArchiver archiveRootObject:myArray toFile:@"someFile"];
to load it:
NSMutableArray* myArray = [NSKeyedUnarchiver
unarchiveObjectWithFile:@"someFile"];
|
The two nsmutablearray value is getting swap with another in ios |
Why are you checking tableView == pdfListnameTable ?
That should be tableView isEqual:self. pdfListnameTable. Not sure that is
relevant here, but if you have more than one tableView - i'd guess that you
aren't switching to it as there seems to be a lack of an else statement for
that.
|
For Loop with Bool |
Your FS value is a string that includes the newline character from the file
still, so test for a string value:
if FS == '0
':
or strip the newline:
if FS.strip() == '0':
or turn FS into a float first:
if float(FS) == 0:
or strip line while splitting:
line = line.strip().split(';')
Further tips:
Just loop over lines directly; don't use range():
for line in lines:
line = line.strip()
# do something with `line`
Even if you still need an index as well, you use enumerate() to generate
the index:
for i, line in enumerate(lines):
line = line.strip()
# do something with `line` and `i`.
You can use the csv module to handle splitting data files into rows:
import csv
with open(somefile, 'rb') as inputfile:
reader = csv.reader(inputfile, delimiter=';')
|
Objective c Bool always NO |
toggleChrome: sets the isChromeHidden_ variable, it does not toggle it. To
toggle you would write:
- (void)toggleChrome
{
isChromeHidden_ = !isChromeHidden_;
//Find chrome value
NSLog(isChromeHidden_ ? @"YES" : @"NO");
}
!isChromeHidden_ is the opposite value of isChromeHidden_.
|
C++ bool to int cast and GCC 4.8.1 |
Do I understand correctly that bool to int cast should cast true to 1?
Yes.
GCC 4.8.1 gives strange result for this code:
That's because your program has undefined behavior, since your array is not
initialized. Try, for instance, this:
array<bool, 3> bb = { true, false, true };
And you will see a consistent output. Here is a live example.
|
How do I get a bool from a different thread? |
Not sure what you mean
But you could do something like this
bool myBool = false;
this.Invoke(new MethodInvoker(() => myBool = getBool()));
return myBool;
If am wrong pls make me clear
|
imputing bool into my .h |
something like this ?
@interface ViewController : UIViewController
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate,UIAccelerometerDelegate> {
UIAccelerometer *accelerometer;
float xoff;
float yoff;
float xvelocity;
float yvelocity;
float xaccel;
float yaccel;
BOOL FrontCamera;
BOOL haveImage;
UIImageView *capturedImage;
}
|
What should be used bool or exception? |
You should raise an Exception when something not expected happens.
In your case if a user is logging in it is not unexpected that the
procedure fails, he/she might have inserted a wrong password or used a
wrong username password combination.
It would be exceptional if, for example, the database is not found.
Exceptions should not be used as flow control structures, but to handle
those edge, unexpected cases that could happen outside the normal flow of
an application.
Be sure though to return a proper response, in JSON it could be something
like
{
"result": "failure",
"message": "username and/or password not matching to any user"
}
because a simple false is not informative at all.
|
in-place bool AND and OR in c++? |
The answer will be short: no, the C++ syntax does not allow such structure.
You have to use:
something = something || something_else;
However.... if your function returns bool on success (as in, true on
success)... Why don't you just use the following?
someOk = funcReturningBoolOnSuccess(i);
Will it not return false on failure anyway? Seems illogical.
Why don't you just do:
bool someOk=false;
for(int i=0; i<10; i++){
if (funcReturningBoolOnSuccess(i)) {
someOk = true;
break;
}
}
A lot more efficient :)
|
NSUserDefauls BOOL Value is not set in iOS |
setBool:forKey: expects a BOOL. Try using YES or NO instead of true or
false (which is type bool, lowercase).
Also you should access it with boolForKey instead of objectForKey.
Your logic test will always be YES if you've ever set the object in
NSUserDefaults since you're effectively testing if the key exists (i.e. not
nil), not whether it is actually set to YES/NO.
In other words, change:
if ([defaults objectForKey:@"stateForSoundSwitch"]) {
to this:
if ([defaults boolForKey:@"stateForSoundSwitch"] == YES) {
|
c++ bool anomaly -- why is this possible? |
why is this possible?!
Undefined behaviour is just that - undefined. Anything at all could
happen.
if enough memory for 137 is allocated, then why the hell test++; results
in 1?
The language specification defines that behaviour.
|
C# if else, switch, bool |
Because input contains north so first if is executed and not searching for
else if, try to inverse if's and put case5 as first if :)
if (case5)
CaseId = 5;
else if (case2)
CaseId = 2;
else if (case3)
CaseId = 3;
else if (case4)
CaseId = 4;
else if (case1)
CaseId = 1;
|
data not being written to NSMutableArray |
Have you even created your _theNewSource array? It seems like you haven't
done the following:
_theNewSource = [[NSMutableArray alloc] init];
Make sure you are creating your instance before trying to use it.
|
NSSortDescriptor not sorting my NSMutableArray? |
sortedArrayUsingDescriptors does not sort the array in place. It returns a
newly-sorted array.
sortUsingDescriptors does an in-place sort.
|
string array value to NSMutableArray in ios |
If the format is json (as your tags suggest) the easiest way is to use
NSJSONSerialization
Using
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt
error:(NSError **)error
Will get you a foundation class object returned (NSArray, NSDictionary,
depending on the json data)
|
NSMutableArray getting released before ViewDidLoad |
Looking at your updated question, you're setting up that array inside the
scope that starts with // Custom initialization. But what you don't notice
is that viewDidLoad is actually called on this line:
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
That means your array is still nil inside viewDidLoad, and thus
DoUpdateLabel
I would recommend instead initializing that array inside -viewDidLoad
instead, and you'll see the results you're looking for.
|
NSMutableArray search string |
Try using this method on NSArray. Something like this:
return [personArray[[personArray indexOfObjectPassingTest:^ (id obj,
NSUInteger index, BOOL stop) {
return [lastName isEqualToString:[obj lastName]];
}]] phoneNumber];
You get the idea.
|