w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Objective C - NSNumber storing and retrieving longLongValue always prefixes with 0xFFFFFFFF
The problem is this line: [downloadInfo setFileTotalSize:[NSNumber numberWithInt:bytesTotal]]; bytesTotal is not an int, it's a long long, so you should be using numberWithLongLong:, not numberWithInt:. Change it to: [downloadInfo setFileTotalSize:[NSNumber numberWithLongLong:bytesTotal]]; The conversion is causing it to be sign extended to 64 bits, and the number starting with 8 appears to be a negative number so that bit gets extended all the way thru the upper long, causing it to be ffffffff.

Categories : Objective C

Filter NSArray of NSNumber with NSArray of NSNumber with NSPredicate
To find the objects that have at least one genre in the given array a, use [NSPredicate predicateWithFormat:@"ANY genres in %@", a]; To find the objects that have all genres in the given array, a SUBQUERY is needed: [NSPredicate predicateWithFormat:@"SUBQUERY(genres, $g, $g IN %@).@count = %d", a, [a count]]; (The idea is to check if the number of genres that are in the given array is equal to the size of the array.)

Categories : IOS

Bootstrap span's erroneously centered
"I want to have a left and right component so I'm using two span6's." ...Except if your code is the same as the code you posted in your question, you are using one span12, and then one span6. Here's a version that uses two span6 classes. http://jsfiddle.net/FtPZf/ <div id="group_and_date_controls" class="container"> <div class="row"> <div id="group_control" class="span6"> <ul> <span id="new_group">New Group</span> <li class="controlItem">hi</li> <li class="controlItem">hi</li> </ul> </div> <div id="date_control" class="span6 navbar pull-right"> <ul id="thing" class="nav pull-right"> <li>Jun

Categories : CSS

index_ appended to path erroneously added to rails 4 route
It's on the collecion, so Rails appends an _index. If you want to overwrite it, just change to: resources :triage do collection do put :process_multiple, as: :proccess_multiple_triage end end And now you'll be able to use process_multiple_triage_path

Categories : Ruby On Rails

Enum with NSnumber
Since last year WWDC you can use boxed expressions to create NSNumbers: @(INCOMPLETE) // Equals to [NSNumber numberWithInt:INCOMPLETE] See also here: http://clang.llvm.org/docs/ObjectiveCLiterals.html At one point it says it's not available in any Apple compiler but now Clang is the default one which supports this since version 3.2 Or you add a method to your subclass of NSManagedObject taking an enum EventStatus which creates a number and calls the original method

Categories : Objective C

NSNumber from CGFloat
This is how I handled it: @interface NSNumber (CGFloatAdditions) + (NSNumber*)numberWithCGFloat: (CGFloat)value; - (CGFloat)CGFloatValue; @end @implementation NSNumber (CGFloatAdditions) + (NSNumber*)numberWithCGFloat: (CGFloat)value { #if CGFLOAT_IS_DOUBLE return [NSNumber numberWithDouble: (double)value]; #else return [NSNumber numberWithFloat: value]; #endif } - (CGFloat)CGFloatValue { #if CGFLOAT_IS_DOUBLE return [self doubleValue]; #else return [self floatValue]; #endif } @end CGFLOAT_IS_DOUBLE is defined in CGBase.h conditionally by platform.

Categories : Objective C

Set Precision for NSNumber value
Problem Solved!..... Thanks for everyones input but yea.... it was a string. Martin R, thanks for you debugging code. And understanding _NSCFString is really just a wrapper for an NSString but they were mainly the same. Here was my solution... nowValue outputs : 24.14295959472 nowValue = [now objectForKey:@"value"]; NSNumberFormatter * f = [[NSNumberFormatter alloc] init]; [f setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber * nowNum = [f numberFromString:nowValue]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterDecimalStyle]; [formatter setMaximumFractionDigits:2]; nowValueFormatted = [formatter stringFromNumber:nowNum]; nowNum outputs : 24.14

Categories : IOS

NSNumber property is nil
Going off of one of your screenshots, it looks like the object at index 3 is a BOOL. Just do this: self.repeat = [NSNumber numberWithBool:[dataArray objectAtIndex:3]]; That's always going to return either 0 or 1 though, so take that for what you will.

Categories : Objective C

Wrong value from NSNumber to enum
try to write your enum function like this:- typedef enum myStates { option0 = 0, option1, option2, option3 } MyState; and print both as individual like what output your notification has and what output your myState object has.

Categories : Iphone

Testing NSNumber for nil in isEqual
Generally when writing an equality method you should: Check the class of the object being compared first Check the local object and the compared object properties for nil Check the local object and the compared object properties for equality If you are being passed NSNull instead of nil then that is an error in your JSON handling and validation which needs to be fixed. You also need to check the nil case explicitly as nil == nil is true but [nil isEqual:nil] is false.

Categories : IOS

converting value from dictionary to NSNumber
Both NSNumber and NSString respond to the methods -intValue which returns an int. You can therefore do something like: NSNumber *myNumber = @([[dictionary valueForKeyPath:@"key.path"] intValue]); // using modern Objective-C syntax

Categories : IOS

Custom Formatting of an NSNumber
This may be useful: https://discussions.apple.com/thread/2399192 Key quote: Parentheses and dashes are not allowed in a number format.

Categories : Iphone

NSNumber in NSDictionary is always null
I've run your code and I could reproduce the problem. But it seems like a debugger problem. For instance, if after your dictionary is created, go to the console and try printing the dictionary. po dictionary My result is like: $4 = 0x2083e770 { number = 1; } So it's not null at all. Also, after that, anum is assigned correctly and b is set to YES. So it really looks like a debugger issue instead of a bug from you.

Categories : IOS

NSPredicate for two NSNumber arrays
The ANY operator will handle that. Since it is a bit difficult to say from your question which of the arrays is "self" in normal predicate parlance, I'll write it without a self: NSArray *arrayA = @[@2, @3, @7]; NSArray *arrayB = @[@2, @4, @9]; NSPredicate *pred = [NSPredicate predicateWithFormat: @"ANY %@ IN %@", arrayA, arrayB]; Due to the lack of a "self", it will have to be evaluated with nil as the object, but that works fine: BOOL matched = [pred evaluateWithObject: nil]; If you prefer to have a "self" in the predicate, you can just enter it: NSPredicate *pred = [NSPredicate predicateWithFormat: @"ANY self IN %@", arrayB]; BOOL matched = [pred evaluateWithObject: arrayA]; The result is the same. A small conceptual comment The predicate above evaluates to true if any inte

Categories : IOS

Converting an NSNumber to NSTimeInterval
In both cases, you use [[[userDefaults objectForKey:groupTitleForReference] objectForKey:@"time"] doubleValue] to get the double value. You need to concentrate on what might be different. Off the top of my head, look at: Is interval correctly declared as a double or NSTimeInterval? Show us how and where you declare interval. When you display interval to check its value, are you displaying it correctly. I've been known to do this by accident NSTimeInterval interval = .... NSLog(@"%@", interval); Show us the code you use to inspect the interval and its output. Has userDefaults changed? Has groupTitleForReference changed. EDIT Another thing to check If interval is a global make sure the declaration in the header is of the form extern NSTimeInterval interval; If you omit e

Categories : Objective C

iphone-Array Won't Add NSNumber
After this line: NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:choice]; You need to check that array is not nil. It will be nil if no file exists (or the file contents are invalid). So: if (array == nil) { array = [NSMutableArray array]; }

Categories : Iphone

Python zipfile module erroneously thinks I have a zipfile that spans multiple disks, throws BadZipfile error
I get the same error on a similar file although I am using python 3.4 Was able to fix it by editing line 205 in zipfile.py source code: if diskno != 0 or disks != 1: raise BadZipFile("zipfiles that span multiple disks are not supported") to: if diskno != 0 or disks > 1: Hope this helps

Categories : Python

Converting Dictionary key values into NSNumber
You can access Required values for your keys in this manner. NSArray * array = [dic objectForKey:@"branches"]; NSDictionary *furtherNames = array[0]; NSNumber *latitude = [NSNumber numberWithFloat:[[furtherNames objectForKey:@"latitude"] floatValue]]; NSNumber *longitude = [NSNumber numberWithFloat:[[furtherNames objectForKey:@"longitude"] floatValue]]; All you need to observe is that () => Array of objects, {} => Dictionary. Hence traverse them accordingly. Hope this helps.

Categories : Objective C

Use NSNumber and NSUserDefaults to do a simple computation
Examine your expression, on the left-hand-side of - you have: [[NSUserDefaults standardUserDefaults] objectForKey:@"AmountToSpend"] What is the value of that expression? It is some reference to an object. Now the rhs is: sum and the value of that expression is some reference to an NSNumber. So what is the value of: <some reference to an object> - <some reference to an `NSNumber`> You are asking for the difference between two references, hence the error: Arithmetic on pointer to interface 'id', which is not a constant size for this architecture and platform. You need to obtain the numeric value your objects represent, do your arithmetic on those, and then convert the numeric result to a string representation to assign it to your text property. NSNumber has various met

Categories : IOS

Why objects like NSString and NSNumber cannot be overwritten?
When you write foo = @"Hello World!";, foo was pointing to an NSString object that has the data "Hello World!", let's say that this object resides at address 10. When you write foo = @"Hello everybody!", foo now points to a new object that has the data "Hello everybody!", let's say that this object resides at address 50. The first object wasn't modified at all, you just made foo point to another object at another address. If those strings were mutable, you could modify the content, NSMutableString *foo = @"Hello World!".mutableCopy; //LEt's say, it's @ adress 10 [foo appendString:@"How is it going?"]; // IT's still @ adress 10, but with new content. foo now points to an object at address 10, that has modified content "Hello World!How is it going?". In the first case, you couldn't mo

Categories : Objective C

NSNumber and MySQL NULL values
I would create the NaN number different: [NSDecimalNumber notANumber] The division by zero leads to an undefined state, if I remember the standard correct. But beside this I think, that it is okay.

Categories : Objective C

Increment NSNumber inside the GCD Block
Pointers inherited from a block are considered "read-only". In order to modify the value you need to prefix it with __block. In your case you cannot prefix value with __block because it's an argument. Even if you could, your GCD block is asynchronous, and would return before your CGD block was called. For what you're trying to do, you need to do something like this: - (void)doSomethingIntensive:(NSNumber *)value complete:(void (^)(NSNumber *result))complete { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_async(queue, ^{ if (complete) complete(@(value.integerValue + 1)); }); } You would call such a function like this: [doSomethingIntensive:@(1) complete^(NSNumber *result) { NSLog(@"%@", result); }); The general

Categories : Objective C

Setting NSNumber to NSManagedObject attribute
It is a very bad idea use id as property name. id is a type, namely a generic pointer to a generic object and I think that this create more than one issue, now or in the future. In Core Data, I usually create the unique identifier property with the following format ID, i.e. for the class Post i will have @property (nonatomic, retain) NSNumber *postID;

Categories : Iphone

Convert long NSString to NSNumber
This is how you do it: unsigned long long number = [[jsonArray objectForKey:@"next"] longLongValue]; NSNumber * numberValue = [NSNumber numberWithUnsignedLongLong:number];

Categories : IOS

NSNumber, what to be aware of when using and storing different primitive types
It shouldn't make a difference. As I understand it, when you allocate an NSNumber, it reserves a specific amount of memory as required in order to represent itself. When you make changes to the value of an NSNumber it should still be taking up the same amount of size in the database regardless of what actual value it's holding (same way an int is still an int whether it's set to 1 or 2147483647). I'm too lazy to check, but if you're in xcode under openDeveloperTools>instruments there's an allocations tool and a leaks tool. You could run a for-loop and intentionally leak @(int) values, then @(longlong) values and see if there's a difference in how fast it consumes heap.

Categories : Iphone

Why is [NSNumber numberWithBool:YES] reported as null by debugger?
Xcode 4 debugger lies. (See comment above by Herrman Klecker) Ignore the grey color text "(null)". Look at this question, Xcode debugging: View value of NSNumber?, for tips on displaying actual values. One way… Set breakpoint after your code, click into the debugger Console View, and use the Print Object command by typing po y. Press Return/Enter to execute the expression and see resulting value in the console. The commands p and po work in both the older gdb and newer lldb debugger technologies. See Debugging tips for Objective-C programming for examples. Another way… Open the Debugger view and in the Summary column enter something like: {(int)[$VAR intValue]}

Categories : Objective C

converting nsinteger to nsnumber strange number
You shouldn't use NSInteger as a reference. Try removing the * from behind every mention to NSInteger you do. Remember, NSInteger are not objects, they're just a cool way to name "int"s :)

Categories : Objective C

Cocoa persist coredata NSNumber from tableview not working
As stated in the docs for Custom Value Transformers (Value Transformer Programming Guide) A value transformer subclass must implement the transformedValueClass class method. This method returns the class of the object that the transformedValue: method returns. Thus, your transformedValueClass returns the class for NSNumber, but your transformedValue: method returns an instance of type NSString Since you're converting from an NSString to an NSNumber, I imagine you'll want to swap the implementations of your transformedValue: and reverseTransformedValue: methods.

Categories : Objective C

iOS: NSNumberFormatter doesn't convert string back to NSNumber
100,00096 isn't correct... Do you mean one of these? [[self.currencyFormatter numberFromString:@"£10000096"] integerValue] [[self.currencyFormatter numberFromString:@"£100,000.96"] integerValue] [[self.currencyFormatter numberFromString:@"£100000.96"] integerValue] [[self.currencyFormatter numberFromString:@"£10,000,096"] integerValue]

Categories : IOS

Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
You appear to be trying to set your array directly to your number / string (which you aren't actually getting out of obj so your code shouldn't compile...). You also don't need the arrays to create the dictionary. You can just do: for (MyTestSp_GetTrainingCounts *obj in objReturnTrainings) { dictTrainings[obj.trainingName] = obj.trainingCount; }

Categories : IOS

How to use NSNumber or CGFloat constant in Autolayout visual format language?
You need to pass kTopAndBottomPadding in the metrics dictionary, not the views dictionary. Also, you might want to just take advantage of the addConstraints: method instead of messing about with mutable arrays and for/in loops. CGFloat const SPMTVC_kTopAndBottomPadding = 5.0; // ... NSDictionary *metrics = @{ @"kTopAndBottomPadding" : @(SPMTVC_kTopAndBottomPadding) }; NSDictionary *views = @{ @"messageTextView" : _messageTextView, @"contentView" : self.contentView }; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[messageTextView(==contentView)]-0-|" options:NSLayoutFormatAlignAllLeading metrics:metrics views:views]]; [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-kTopAndBotto

Categories : Iphone

sending NSNumber *_ strong to parameter of incompatible type of float
The line: [slider setValue:sliderValue]; needs to be: [slider setValue:[sliderValue floatValue]]; The value property of slider is of type float. You can't simply pass an NSNumber reference. BTW - NSUserDefaults has direct support for float values: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setFloat:slider.value forKey:@"slider"]; slider.value = [defaults floatForKey:@"slider"];

Categories : Iphone

only property-list objects (NSNumber) in NSDictionary but not able to store dict in UserDefaults
Your dictionary must be like this: NSDictionary *defaultSetting = [[NSDictionary alloc] initWithObjectsAndKeys: one, @"one", two, @"two", nil];

Categories : Misc

Obj-C: Incompatible pointer types assigning to 'UITextfield *_strong' from 'NSNumber *_strong
You want to set UITextField's text property. [incomePerHour setText:[resultNumber stringValue]]; Bye ! EDIT : You can also do it without the NSNumber : [incomePerHour setText:[NSString stringWithFormat:@"%f", hourlyIncome]]; You'll have less precision due to %f (rounds to 6 decimal by default), but you can use %.42f if you want 42 decimals.

Categories : Iphone

Filter NSArray of Object with NSArray of NSNumber with NSPredicate
once check this one, NSArray *filteredObject = [questionSections filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.Carl contains %@ OR self.Carl contains %@ ",@"1",@"2"]]; EX:- NSArray* questionSections=[[NSArray alloc] initWithObjects:[[NSDictionary alloc] initWithObjectsAndKeys: @"List 3 rooms in your house?",@"name",@"301q.png",@"questionpicture",nil],[[NSDictionary alloc] initWithObjectsAndKeys:@"Name a commonbird?",@"name",@"202q.png",@"questionpicture",nil], nil]; NSArray *filteredObject = [questionSections filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self.questionpicture contains %@ OR self.questionpicture contains %@ ",@"2",@"3"]]; NSLog(@"%@",filteredObject); O/P:-- ( { name = "List 3 rooms in your house?";

Categories : Objective C

Rails form_authenticity_token returns nothing session[:_csrf_token] returns the actual token
I think the docs you quoted implies that this method, form_authenticity_token() is only accessible in the Controllers (class: ActionController::RequestForgeryProtection). You should use the session[:_csrf_token] directly OR you could set a shared variable: # in controller def my_action @auth_token_form = form_authenticity_token end # in view %input{name: "authenticity_token", type: "hidden", value: @auth_token_form}

Categories : Ruby On Rails

QThread emits finished() signal but isRunning() returns true and isFinished() returns false
The way the QThread lifecycle works is like this: You call QThread::start(). At this point, isRunning() should start returning true. The thread internals start. They emit the started() signal. The thread internals call run(). Unless you override this in a subclass, run() calls exec(). exec() enters an event loop and stays there until quit() or exit() is called. exec() and run() return to the internals. At this point, isFinished() should start returning true and isRunning() false. The internals emit the finished() signal. The internals do some final cleanups. The thread terminates for real. So you need to call quit() after your location fetcher is done - but this->quit() isn't calling quit() on the thread! This is probably why it's not doing anything. Your code looks a bit like it w

Categories : C++

Neo4j Spatial 'WithinDistance' Cypher query returns empty while REST call returns data
this is a bug, see https://github.com/neo4j/spatial/issues/106 if you want, feel free to investigate, seems to be the iteration in SpatialRecordHits.java! Meanwhile, make sure to add the node to the index before querying via the index, as that creates the proper node structure.

Categories : Neo4j

Web Api of content-type XML returns complete class - while JSON returns just ID
@Will that was it! I have to go back and add "[DataContract]" to my classes and "[DataMember]" to the members and the data then comes through. http://msdn.microsoft.com/en-us/library/ms733127.aspx namespace MyTypes { [DataContract] public class PurchaseOrder { private int poId_value; // Apply the DataMemberAttribute to the property. [DataMember] public int PurchaseOrderId { get { return poId_value; } set { poId_value = value; } } } }

Categories : C#

Attempting to create a read-only property attribute - getter returns initialized value, direct access returns changed value
I use property as decorator. It convenient for calculating data. May be for make read-only attribute better use magic function as __set__ and __get__?

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.