nsarray

How to deal with [NSDate] and Firebase

流过昼夜 提交于 2019-12-06 04:13:19
问题 I am making a calendar app. I have one array of selected dates. User selected it previously and they are stored there. var selectedDays = [NSDate]() When app loads I have to display these dates, but everything is overcomplicated because Firebase doesn't accept NSDate I have another array var selectedDaysForFirebase = [String]() which is the same array as above only dates are converted to strings to accomodate Firebase. This is how I save selected dates: // 1. Append converted date into

NSDictionary Vs. NSArray

瘦欲@ 提交于 2019-12-06 03:58:34
问题 I am reading on objective-c (a nerd ranch book), and I can't help thinking about this question: How do I decide which collection type, NSArray or NSDictionary (both with or w/o their mutable subclasses), to use when reading content from URL? Let's say am reading JSON data from a PHP script (a scenario am dealing with), which to use? I know it is stated in many references that it depends on structure of data (i.e. JSON), but could a clear outline of the two structures be outlined? Thank you

Objective C Class or struct?

廉价感情. 提交于 2019-12-06 01:31:20
问题 I have a class Song with properties Title, Key, Artist, etc. There are no methods. I loop through a database of song information and create a Song object for each, populating the properties, and then store the Song objects in an NSArray. Then I thought, why not just have a struct Song with all those same properties instead of a class Song. Doing so would eliminate the class files, the #import Song line in the using class's .m file, and the need to alloc, init, release. On the other hand, I'd

Searching a NSArray for the nearest number(s)

梦想与她 提交于 2019-12-06 00:51:34
问题 Is there an easy way to search an NSArray of numbers to find the nearest (or exact if it exists) matches to a user-input number? Say I have an array like this: 7, 23, 4, 11, 18, 2 , and the user enters 5 . The program returns the three nearest values in descending order of closeness: 4, 7, 2 , and most importantly gives the NSArray index of the three objects: 2, 0, 5 . 回答1: Update: see below for a better solution than my first one. Here's a solution using NSDictionary wrappers for each number

iOS - Make a copy of a array object into another

随声附和 提交于 2019-12-05 22:59:29
I have a little problem, and I need help. I want to loop through a multidimensional array, and every time I find a value for a key ex."name" that is equal to ex. "Hello". I want to copy that array object into another array. How do I do that? I assume you have a 2-dimensional array and since I don't know how your objects within the array look like I take the id type and the method valueForKey : NSMutableArray *tmp = [[NSMutableArray alloc] init]; for(NSArray *dim1Array in yourMultidimensionalArray) { for(id obj in dim1Array) { if([[obj valueForKey:@"name"] isEqualToString:@"Hello"]) { [tmp

Swift optimization level breaks converting NSArray to Array

两盒软妹~` 提交于 2019-12-05 22:28:29
问题 The following (somewhat contrived) code works when Swift Optimization Level is set to None [-Onone] (default for debug): let nsa = NSArray(array: ["foo", "bar"]) let a = nsa as [String] But the app crashes (crash log) during run-time when set to Fastest [-O] (default for release). I luckily discovered I can work around the issue by doing this: let a = nsa as [AnyObject] as [String] My question is two-fold: Could you help me understand why this is happening? Is there a better way to convert an

Find index of an NSArray by passing value

北慕城南 提交于 2019-12-05 21:38:19
问题 Is it possible in an NSArray to find out if a given value exists or not in the array (without searching it using a for loop)? Any default random method. I went through the documentation, but didn't find much relevant. Please also tell me about valueForKey method (I was unable to get that from doc). 回答1: The containsObject: method will usually give you what you're asking - while its name sounds like you are querying for a specific instance (i.e. two object with the same semantic value would

Symbolic exception breakpoint on -[NSRangeException raise]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 21:33:58
Adding a symbolic breakpoint in Xcode gives you an example template of -[NSException raise] . I want to do the same thing but specifically on -[NSRangeException raise] . The reason being that I want to breakpoint only on specific array bounds exceptions, for example: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 31 beyond bounds [0 .. 30]' Yes, I know that I can add a catch all exception breakpoint. However, I do not want to do that as I do not want to breakpoint on the many exceptions generated throughout using the app. I've

Does the removeAllObjects method of an NSArray or NSMutableArray release memory?

六月ゝ 毕业季﹏ 提交于 2019-12-05 18:39:14
I need to know if the removeAllObjects method of an NSArray or NSMutableArray releases memory. If my array has got 10000 elements. Can I use the [array removeAllObjects]; to release the memory and reload it with other elements? Or it leaks memory? Thanks EXAMPLE if the size of my NSMutable array is 20mb with 10.000 elements for example... if I use the removeAllObjects method...will its size be 0mb? An NS[Mutable]Array is a collection of references to object. Calling -removeAllObjects nils those references. The capacity and memory used by the array itself stay the same. In the case of

UIPickerView crashes app when user is spinning components at the same time

旧巷老猫 提交于 2019-12-05 17:53:40
I've got really unbearable issue with UIPickerView. There're 2 components: first one with food categories, and second with foods inside each category. I've got proper arrays with foods, which looks like: ViewController.h @property (strong, nonatomic) NSArray *leftPickerDataSource; @property (strong, nonatomic) NSArray *vegetablesDataSource; @property (strong, nonatomic) NSArray *eggsDataSource; @property (strong, nonatomic) NSArray *pastaDataSource; @property (strong, nonatomic) NSArray *riceDataSource; @property (strong, nonatomic) NSArray *meatDataSource; ViewController.m ... @implementation