nsarray

Unable to get Array Value in SWIFT

人走茶凉 提交于 2019-12-13 03:55:29
问题 I retrieved values from parse and stored one by one in an array called "sto_tit". But if I try to print the values, I unable to print. It is get printed inside loop only, but not get printed Outside FOR LOOP or OUTSIDE ELSE block, I don't know what error in my code. Kindly guide me! MY CODE BELOW: func parse_db() { var sto_tit = [String]() // EITHER GLOBAL DECLARATION or INSIDE BLOCK, SAME ISSUE // FACING par_query.selectKeys(["story_title"]) par_query.findObjectsInBackgroundWithBlock({

parsing txt from array to UILabel

匆匆过客 提交于 2019-12-13 03:54:01
问题 I'm actually starting to loose the will to live, this piece of code is driving me nuts! I'm trying to get the content of mathspractice.txt into *myLabel I'm using an array which is: -(void)loadText { NSArray *wordListArray = [[NSArray alloc] initWithArray: [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”mathspractice” ofType:@”txt”] encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@”\n”]]; self.theMathsPractice = wordListArray;

NSArray has objects yet UICollectionView is appearing empty

元气小坏坏 提交于 2019-12-13 02:49:30
问题 I've been working on this project to expand my portfolio. I am still rather new to objective-c, so help would be highly appreciated! I have been tinkering with this code for a few days now. I am aware the labels work, as I was able to get all the cells to display the same information (not the desired result). This was likely to a fault where my array didn't store all the objects. Below is the code for my UIViewController; INITIAL PROBLEM So I have confirmed that the NSLog, displays 8 objects

Constant bugs from [NSArray count] being unsigned

你说的曾经没有我的故事 提交于 2019-12-13 02:30:15
问题 I'm creating bugs over and over by failing to notice the consequences of [NSArray count] being unsigned . Today's example is relatively unusual: for (int i = -1; i < [myArray count]; i++) { This loop never executes! You need (int)[myArray count] . My usual mistake is: for (int i = 0; i < [myArray count] - 1; i++) { If the array is empty, this loop executes basically forever because [myArray count]-1 overflows the unsigned int . I do use fast enumeration where possible, but in this project I

addObjectsFromArray: not copying into global NSMutableArray

青春壹個敷衍的年華 提交于 2019-12-13 02:03:22
问题 So here is a partial sample of the relevant code. static NSMutableArray *radioInputArray; static NSMutableArray *buttonsArray; - (IBAction)lookForRadioButtons:(id)sender { // NSLog(@"Testing"); NSError *error; NSString *radiostr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"getRadios" ofType:@"txt"] encoding:NSASCIIStringEncoding error: &error] ; if (radiostr == nil) { NSLog (@"Error! %@", error); } else { NSLog(@"%@",radiostr); NSString *radiotxt= [webView

How to add object to NSArray with key from database?

倖福魔咒の 提交于 2019-12-13 00:49:20
问题 How to add object to NSArray with key from database? i am using FMDatabase class to open database, its work ok, my problem is how to add object with key to NSArray, see this code @implementation ViewController { NSArray *allDevices; NSArray *searchResult; } - (void)viewDidLoad { [super viewDidLoad]; FMDatabase *db = [FMDatabase databaseWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"db.sqlite"]]; [db open]; FMResultSet *results = [db executeQueryWithFormat:@

Retrieving values from 2D array in JSON string

孤者浪人 提交于 2019-12-12 19:33:18
问题 We fetch some JSON data using a REST protocol like this. jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) Which looks like this: jsonResult: ( { board = "[[\"1:\",\"Y\",\"U\",\"P\"]]"; }) From this we get a game board like so: if let boardContentArray = jsonResult[0]["board"] as NSArray?{ print("boardContentArray: \(boardContentArray)" ) } else { print("board element is not an NSArray") } The boardContentArray looks like this: It i

Array of objects from array passing test

早过忘川 提交于 2019-12-12 18:15:16
问题 I have an NSArray of objects, which have a property id . I then have another NSArray with a selection of ids. I need to get all the objects in the first array which have the ids listed in the second array. Is it possible to do this without for loops (well 1 for loop is ok, but I'd like to avoid it). I know how to do this with 2 for loops, but this seems very inefficient. So basically I'm looking for the most efficient way. (The Id is an NSURL btw, so it can't be anything integer specific) 回答1

Search String in NSDictionary store in NSMutableArray

浪尽此生 提交于 2019-12-12 17:03:58
问题 I am trying to search a String in NSDictionary stored in NSMutableArray for (int k = 0; k < [onlyActiveArr count]; k++) { NSString *localID = [onlyActiveArr objectAtIndex:k]; NSLog(@"%@",localID); int localIndex = [onlyActiveArr indexOfObject:localActiveCallID]; NSLog(@"%d",localIndex); for (NSDictionary *dict in self.SummaryArr) { NSLog(@"%@",[dict objectForKey:@"ActiveID"]); if (![[dict objectForKey:@"ActiveID"] isEqualToString:localID]) { NSLog(@"found such a key, e.g. %@",localID); } } }

Sort NSArray's by an int contained in the array

偶尔善良 提交于 2019-12-12 16:17:20
问题 I have an array, let's call it "array" and inside of the array I have objects like this: "0 Here is an object" "4 Here's another object" "2 Let's put 2 here too!" "1 What the heck, here's another!" "3 Let's put this one right here" I would like to sort the arrays by that number, so it'll turn into this: "0 Here is an object" "1 What the heck, here's another!" "2 Let's put 2 here too!" "3 Let's put this one right here" "4 Here's another object" 回答1: You can use NSArray's