nsarray

Loading Array From .Plist

一曲冷凌霜 提交于 2019-12-21 01:39:07
问题 I'm trying to load my array from an array in my .Plist but its not working. The plist looks like this: This is the code I'm using: NSString *path = [[NSBundle mainBundle]pathForResource:@"DiseasePropertyList" ofType:@"plist"]; NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path]; self.myArray = rootLevel; [rootLevel release]; 回答1: Try this. Please change file name. It works fine. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

How do I comfortably use CGColor in an NSArray with CGGradient

▼魔方 西西 提交于 2019-12-20 19:57:11
问题 I have two UIColor instances and want to use them creating a gradient. The code works, but it gives me a warning when I call the arrayWithObject: constructor: warning: Semantic Issue: Incompatible pointer types sending 'CGColorRef' (aka 'struct CGColor *') to parameter of type 'id' I suspect there lurks other issues related to the warning (leaks for instance). Here is the snippet: UIColor *startColor, *endColor; // ... NSArray *colors = [NSArray arrayWithObjects: startColor.CGColor, endColor

Split an NSString into an array in Objective-C

醉酒当歌 提交于 2019-12-20 12:34:38
问题 How can I split the string @"Hello" to either: a C array of 'H' , 'e' , 'l' , 'l' , 'o' or: an Objective-C array of @[@"H", @"e", @"l", @"l", @"o"] 回答1: If you're satisfied with a C array of char s, try: const char *array = [@"Hello" UTF8String]; If you need an NSArray, try: NSMutableArray *array = [NSMutableArray array]; NSString *str = @"Hello"; for (int i = 0; i < [str length]; i++) { NSString *ch = [str substringWithRange:NSMakeRange(i, 1)]; [array addObject:ch]; } And array will contain

NSArray property: copy or retain?

喜夏-厌秋 提交于 2019-12-20 10:38:23
问题 According to this: NSString property: copy or retain? For NSString/NSMutableString, copy is recommended. How about NSArray/NSMutableArray? 回答1: choose copy , unless you have a very specific reason not to, as well as all the supporting code/interface to back that up. i detailed the rationale and several implications here: NSMutableString as retain/copy that example is based on NSString s, but the same applies for NSArray s. 回答2: Since you're asking about NSArray (rather than NSMutableArray),

Using NSPredicate to filter array of arrays

荒凉一梦 提交于 2019-12-20 10:20:51
问题 I have the following situation: NSArray( NSArray( string1, string2, string3, string4, string5, ) , NSArray( string6, string7, string8, string9, string10, ) ) Now I need a predicate that returns the array that contains a specific string. e.g. Filter Array that contains string9 -> I should get back the entire second array because I need to process the other strings inside that array. Any ideas? 回答1: Just for completeness: It can be done using predicateWithFormat: : NSArray *array = @[ @[@"A", @

NSDictionary sort by keys as floats

为君一笑 提交于 2019-12-20 09:59:46
问题 basically I have an NSDictionary with keys and values. The keys are all numbers, but at the moment they are strings. I want to be able to compare them as numbers in order to sort them. eg: If I have a Dictionary like this: { "100" => (id)object, "20" => (id)object, "10" => (id)object, "1000" => (id)object, } I want to be able to sort it like this: { "10" => (id)object, "20" => (id)object, "100" => (id)object, "1000" => (id)object, } Any ideas? Thanks Tom 回答1: Not sure what you are up to –

Why would my NSMutableDictionary be nil?

独自空忆成欢 提交于 2019-12-20 07:57:07
问题 I am trying to store an array in a NSMutableDictionary. However the NSMutableDictionary is null after i have set objects to it. Here is my code any help is appreciated: NSMutableArray *arrTemp = [[NSMutableArray alloc] init]; NSMutableDictionary *dTemp = [[NSMutableDictionary alloc] init]; STStockData *stockData = [[STStockData alloc] init]; for (int i = 0; i < [_arrTickers count]; i++) { // get the ticker from its json form dTemp = [_arrTickers objectAtIndex:i]; NSLog(@"Ticker: %@",[dTemp

Fetch last five values from NSMutableArray

冷暖自知 提交于 2019-12-20 07:44:26
问题 I have a NSMutableArray whose count is 10 and I want to extract the last 5 values and store them in another array. How can I do this? 回答1: I think that - (NSArray *) subarrayWithRange:(NSRange)range (doc) might help you. NSRange theRange; theRange.location = [wholeArray count] - 5; theRange.length = 5; NSArray *result = [wholeArray subarrayWithRange:theRange]; EDIT : Be careful to check that your array has at least five elements, else, subarrayWithRange will throw an exception. 回答2: Use

ios - How get the total sum of float from a NSMutableArray

与世无争的帅哥 提交于 2019-12-20 06:03:12
问题 I created a NSMutableArray which contains a lot of NSString and float DataOrder *addClient = [[DataOrder alloc ] initWithName:[[DataOrder instance]product] price:[[DataOrder instance]price] taille:[[DataOrder instance]taille] suplement:[[DataOrder instance]suplement]]; [[[ArrayBuying instance] tableau]addObject:addClient]; I add the object in my array "[[ArrayBuying instance] tableau]" How can I get the total sum of the float variables ? Thank you 回答1: Something like this will work: float

How to get at a relationship items properties in Core Data?

早过忘川 提交于 2019-12-20 05:46:09
问题 Say you have a Core Data object called Workshop. It has a to-many relationship to a Student object. How would I create an NSArray of the students within the Workshop? 回答1: It's a NSSet opposed to an array, as they are unordered. Use mutableSetValueForKey: This returns a proxy that mutates the relationship and does KVO notifications. Think of the name as "[NS]MutableSet" "valueForKey" rather than "mutableSetValue" "forKey", because it returns a mutable set that you manipulate NSMutableSet