nsnumber

Trouble filtering array of custom objects by an NSNumber using NSPredicate

独自空忆成欢 提交于 2021-01-29 13:28:25
问题 This should be straightforward but something is preventing me from filtering an array of custom objects by NSNumber using NSPredicate. Perhaps it has something to do with the datatype when converting from JSON but I can't figure it out. I download data from a JSON in an array of custom Objects that look like: {"hid":"47","public":"1"} The code to parse the JSON looks like: if (feedElement[@"public"] && ![feedElement[@"public"] isEqual:[NSNull null]]) { newMyObject.pub = feedElement[@"public"]

Errors after changing NSNumber to Int/Double

让人想犯罪 __ 提交于 2021-01-07 06:59:26
问题 I have this class to get data from Firestore: struct Spty: Identifiable{ var id: String var spty: String var r: NSNumber var g: NSNumber var b: NSNumber } class SptyViewModel: NSObject, ObservableObject{ @Published var specialities = [Spty]() @Published var search = "" func fetchData(){ let db = Firestore.firestore() db.collection("specialities").addSnapshotListener { (querySnapshot, error) in guard let documents = querySnapshot else {return } self.specialities = documents.documents

Errors after changing NSNumber to Int/Double

无人久伴 提交于 2021-01-07 06:58:28
问题 I have this class to get data from Firestore: struct Spty: Identifiable{ var id: String var spty: String var r: NSNumber var g: NSNumber var b: NSNumber } class SptyViewModel: NSObject, ObservableObject{ @Published var specialities = [Spty]() @Published var search = "" func fetchData(){ let db = Firestore.firestore() db.collection("specialities").addSnapshotListener { (querySnapshot, error) in guard let documents = querySnapshot else {return } self.specialities = documents.documents

NumberFormatter wrong result for 0.9972

前提是你 提交于 2020-04-19 05:43:18
问题 I have a double: let value = 0.99720317490866084 And a Double extention function: extension Double { func stringWithFixedFractionDigits(min: Int, max: Int) -> String { let formatter = NumberFormatter() formatter.minimumFractionDigits = min formatter.maximumFractionDigits = max formatter.minimumIntegerDigits = 1 let numberObject = NSNumber(value: self) return formatter.string(from: numberObject) ?? "\(self)" } } If I use: value.stringWithFixedFractionDigits(min: 2, max: 2) I get 1.00 but I

Convert Integer to Roman Numeral String in Swift

匆匆过客 提交于 2020-02-26 04:04:29
问题 I am looking to take an Integer in Swift and convert it to a Roman Numeral String . Any ideas? 回答1: One could write an extension on Int , similar to the one seen below. Please note: this code will return "" for numbers less than one. While this is probably okay in terms of Roman Numeral numbers (zero does not exist), you may want to handle this differently in your own implementation. extension Int { var romanNumeral: String { var integerValue = self var numeralString = "" let mappingList: [

NSFileSystemFreeSize

╄→尐↘猪︶ㄣ 提交于 2020-01-14 06:08:04
问题 I get a negaitve number from trying to use this function can anyone help. see code below NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:dbPath error:Error]; NSDictionary *fileSysAttributes = [fileManager fileSystemAttributesAtPath:dbPath]; NSNumber *FileSize = [fileAttributes objectForKey:NSFileSize]; NSNumber *FreeSpace = [fileSysAttributes objectForKey:NSFileSystemFreeSize]; NSLog(@"FileSystem = %@",fileSysAttributes); // gives good values NSLog(@"File Size = %d",

NSNumber >= 13 won't retain. Everything else will

我只是一个虾纸丫 提交于 2020-01-10 16:15:54
问题 The code I'm currently working on requires adding an NSNumber object to an array. All of the NSNumbers with value 0-12 are added fine, but 13 onward causes a EXC_BAD_ACCESS. I turned on NSZombieEnabled and am now getting *** -[CFNumber retain]: message sent to deallocated instance 0x3c78420 . Here's the call stack: #0 0x01eac3a7 in ___forwarding___ #1 0x01e886c2 in __forwarding_prep_0___ #2 0x01e3f988 in CFRetain #3 0x01e4b586 in _CFArrayReplaceValues #4 0x0002a2f9 in -[NSCFArray insertObject

Slider Not Behaving As I Would Expect

此生再无相见时 提交于 2020-01-07 08:11:31
问题 I have a slider that changes a float from 1 to 10 but I want to save this value and use it across all view controllers so I have saved that float as an NSNumber in a model class (settingsData.sensitivitySliderSettingValue). I am trying to output the updated slider value to the console every time that it is changed however it just gets set to 0 rather than 0 to 10. I don't understand why this is... Here's my code: -(IBAction)sensitivitySliderValueChanged:(id)sender { [self updateSensitivity];

What is the most efficient way to generate a sequence of NSNumbers?

佐手、 提交于 2020-01-06 20:06:45
问题 It's a fairly simple builtin in python for example: x = range(0,100) How can I accomplish the same feat using objective-c methods? Surely there is something better than a NSMutableArray and a for-loop: NSMutableArray *x = [NSMutableArray arrayWithCapacity:100]; for(int n=0; n<100; n++) { [x addObject:[NSNumber numberWithInt:n]]; } Yes, I am aware that doing this is most likely not what I actually want to do (ex: xrange in python), but humor my curiosity please. =) Clarification: I would like

Store NSInteger in Core Data

不羁的心 提交于 2020-01-06 05:39:25
问题 Is there any way I can skip dealing with NSNumber and work directly with NSInteger? 回答1: Core Data will only allow NSNumbers. However, you can write custom getters and setters to use NSInteger properties. mogenerator is a wonderful tool that does that automatically for you: it generates classes with native properties for all your entities. 回答2: No. NSInteger is just a typedef for a long integer, not an object. Actual implementation: #if __LP64__ || NS_BUILD_32_LIKE_64 typedef long NSInteger;