FAQ Database Discussion Community


re-populating a tableview with new array elements when a cell is clicked in swift

ios,uitableview,swift,nsarray
thanks for all the help so far. I need, when a cell in UITableView is clicked, to re-populate the view with an array read from another class - just can find a way to refresh the view. Code as follows: Thanks in advance - the help so far has been...

Core Data and a UIActivityViewController

objective-c,core-data,nsmutablearray,nsarray,uiactivityviewcontroller
I have my app that is using core data to persist data. I have a UIActivityViewController setup on my main VC. Everything is working as I expect it to. My question is when you go to grab items from a core data model, how do you have it give you...

OC call one swift function which returns an int array, but can not accept its element with an int variable

objective-c,swift,nsarray
I write a swift function which return an int array and call it in objective-c. But i can not assign the element of the return array to an int variable. (TotalRoute is an int array in swift) This is the function in class GetRoute func returnTotalRouteX()->[Int]{ println("call returnTotalRouteX") var routeX...

Objective C - How do I convert this NSArray to an NSDictionary so I can look up city names by zip code?

ios,objective-c,arrays,nsarray
I use Parse as my backend, and have a cloud function (written in javascript) that just returns an array var providerZIPToCity = [ {zip:"48393", city:"WIXOM, MI"},{zip:"48116", city:"48116, MI"},{zip:"48114", city:"BRIGHTON, MI"},{zip:"48189", city:"WHITEMORE LAKE, MI"},{zip:"48178", city:"SOUTH LYON, MI"},{zip:"48168", city:"NORTHVILLE, MI"},{zip:"48167", city:"NORTHVILLE, MI"},{zip:"48375", city:"NOVI, MI"},{zip:"48374", city:"NOVI, MI"},{zip:"48165", city:"NEW HUDSON, MI"},{zip:"48377", city:"NOVI, MI"},{zip:"48390", city:"WALLED...

Sorting array of objects by 2 attributes of date

ios,objective-c,sorting,nsarray
I have an NSArray of CoreData objects, inside I have 2 attributes: month and year. I want to sort the array by years then by months. DbDate 1: month: 04 year: 2010 DbDate 2: month: 04 year: 2012 DbDate 3: month: 06 year: 2011 DbDate 4: month: 05 year: 2015...

Delete text after #example iOS

ios,objective-c,nsstring,nsarray
How can I erase a part of NSString or NSArray after a word, for example #gallery-1 or after two "skip lines" ? And is it possible to delete a sentence that appears every time ? I would like to erase all the text after #gallery-1 or after 2 skip lines...

Returning NSArray element

objective-c,nsarray
In MRC code returning NSArray element like this: NSString* MyName() { NSArray *names = [NSArray arrayWithArray:[[NSHost currentHost] names]]; return [names objectAtIndex:0]; } void BullCrap() { NSString *wouldItBeRetainedAutomatically = MyName(); } wouldItBeRetainedAutomatically in BullCrap() scope? I am assuming I don't need to send wouldItBeRetainedAutomatically retain message to make sure it is...

UITableView is crashing on NSArray index 1 beyond bounds

ios,objective-c,uitableview,nsarray
My table keeps crashing. "Index 1 beyond bounds". I return the an array count for the number of rows in the section, but as soon as I scroll to the second row (index 1) the app crashes. I have two sections. One with a set number of rows and the...

Add segments from a UISegmentedControl to an NSArray

ios,objective-c,nsarray,uisegmentedcontrol,for-in-loop
I'm trying to add 2 segments to an array, then loop through its subviews. Here is my code: NSArray *myArray = [[NSArray alloc] initWithObjects:[self.segment.subviews objectAtIndex:0], [self.dataSegmentedControl.subviews objectAtIndex:1], nil]; for (id innerView in myArray) // I tried "myArray.subviews" but it didn't let me do ".subviews" { if ([innerView isKindOfClass:[UILabel class]]) {...

how to check all object in NSMutableArray same value

nsmutablearray,nsarray
I have on NSMutableArray like this: NSMutableArray *array = [NSMutableArray arrayWithObjects:@"0",@"0",@"0",@"0",@"0", nil]; now I want check if all object in my array are to same and equal to 0 doing certain work!!!. but I don't know about this. please guide me....

Overwriting NSMutableArray loaded from NSUserDefaults

objective-c,arrays,nsmutablearray,nsarray,nsuserdefaults
So I'm having real problems overwriting an array stored in NSUSerDefaults. Basically I have a checklist of 100 items (defined by bools in an array(which are actually strings at the moment)) and I need to save if each item is checked so when the app loads, the checklist remains as...

search NSArray with regex

objective-c,regex,nsarray
I have an array of names. If any of the name is already there then on inserting new name I want to append the counter eg John (02) if John already present in array then John (03) if it is third entry of name John. Is there any way to...

Converting anyobject to string in Swift

xcode,swift,nsarray
Currently, testArray is an AnyObject. I'm trying to convert testArray[0][0], which is represented by testScoreOne to a string, rather than an anyObject. I don't have any anyObject declarations in my code, so I'm not sure where Xcode is getting this declaration from. @IBAction func loadData(sender: NSArray) { if let testCompositeArray:NSArray...

Most efficient way to create an NSMutableArray from NSArray

objective-c,cocoa,cocoa-touch,nsmutablearray,nsarray
Which of these, if either, is more efficient? NSMutableArray *array = [NSMutableArray arrayWithArray:@[@1, @2]]; or NSMutableArray *array = [@[@1, @2] mutableCopy]; Or are these the same internally?...

mutating method sent to immutable object' in nsmutablearray

ios,objective-c,loops,nsmutablearray,nsarray
I want to remove objects from NSmutableArray can one tell me the Best way to remove from NSMutableArray .h @property(nonatomic,retain)NSMutableArray *arr_property; .m _arr_property=[[NSMutableArray alloc]init]; MTPop *lplv = [[MTPop alloc] initWithTitle:SelectProperty(APP_SHARE.language) options:[_arr_property valueForKeyPath:@"property_list.property_type_name"] handler:^(NSInteger anIndex) { txt_Property.text=[[_arr_property valueForKeyPath:@"property_list.property_type_name"] objectAtIndex:anIndex]; NSLog(@"index number...

Find index of all duplicate elements in NSArray

ios,objective-c,nsarray
It's hard to explain why I need index of duplicate elements in array. When I tried to fetch the index of element in traditional way it shows only one index, but I need to fetch the all index of duplicate values for ex: NSArray *[email protected][@"one",@"one",@"one",@"two",@"two",@"four",@"four",@"four"]; int index = [array indexOfObject:element];...

Trouble Reassigning NSArray values in objective C

ios,objective-c,xcode,for-loop,nsarray
I'm having trouble with a basic for loop in objective-c. I'm a little new to this language, but I'm trying to pull off the following: for(int i=0; i<[yVals count]; i++) { yVals[i] = exp(yVals[i]); } Where yVals is an array of doubles in NSArray. However, I get this error in...

Looping through on NSArray objects with button taps

ios,objective-c,nsarray
I have an array of NSStrings, what I'd like to use as a source for a UIImageView's image names. When the user taps a button I load a new image - next object from the array - into the same image view, that would be the final goal. Actually I...

How to store multiple values for the same key in an NSDictionary, given an NSArray of JSON objects?

ios,objective-c,json,nsarray,nsdictionary
I know it's not possible to set multiple values for the same key, unless the values are stored in an array. I have this NSArray called friMainDicArray of JSON objects: { day = 0; "end_time" = "17:30"; "english_event" = "Lion Dance"; "english_performer" = "Legendary Group"; "image_link" = "schedule_miss_vn"; stage =...

using storyboards

ios,objective-c,xcode,nsarray
I am trying a tutorial for using story board from ray. I am using a tab bar controller connecting a tableview embedded with navigation controller, and this table view is named as players and a view controller connecting tab bar controller named as gestures. Displaying players game, name and rating...

Swift: Check which value in NSArray is closest to another given value

swift,integer,nsarray,cgfloat
Lets say I have an array var values:[CGFloat] = [-12.0, 450, 300] I need to find out which of these numbers is closest to a given value, say var givenValue:CGFloat = 64 Is there an efficient way to find out which object in the array is closest to 64? I...

"NSArray' does not have a member named 'append'

ios,objective-c,swift,nsarray
I just got into swift coding and I am trying to follow a tutorial. but it seems as if the coder I'm following may have an older version, or I am doing something wrong. I am trying to make a sound object to make a soundboard. but when i try...

Sort Array with multiple items

ios,arrays,nsarray
I am looking to sort an array and manipulate it. The array comes from a scraped XML file on the server and is the following: { award = Varies; deadline = "3/1"; description = "To be considered for many Northeastern scholarships, you must apply for admission, submit a high school...

If statement with NSNumber array

objective-c,arrays,nsarray,nsnumber
All I want to do is check if the NSNumbers at the given indexes in the array gameBoard add up to 3... I am new to Objective-C and I am unsure of all these NSNumbers... Can someone help me out? This is what I have.... I presume the == is...

How is my array count 0?

arrays,swift,nsarray,uipickerview,nsxmlparser
I have a UIPickerView. I have a blank array set up until my code parses an XML request. So when it does I want it to populate the array with that data. Below is how I have everything set up. var pickerData = [] func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int)...

how to convert Uk time to Mexico time zone

ios,objective-c,nsarray,nsdate,nstimezone
I am having an array in that date are in UK time zone. I want to convert that UK time zone to below country time. I am having two radio button Mexico (UTC-6) India - IST (UTC+5.30) when i click Mexico (UTC-6) radio button my array date are convert to...

Why would an array try to access beyond it's bounds in a for-loop?

objective-c,nsarray
I've never seen this happen before. I have an NSArray populated with 6 objects. I loop through the array grabbing the values, using just an average, simple for-loop: for (int i = 0; i <= self.myArray.count; i++) { CustomClass *stopTimes = [self.myArray objectAtIndex:i]; NSLog(@"Hey this number %d: at this time...

Objective C: Array with size repopulate

ios,objective-c,arrays,nsarray
I need an array where I can store 3 values, and calculate the average of it. After 3s the array is full, I would like to refresh every value starting from begin [0] of the array. So every 3s the the array is updated and I have the most recent...

Parsing excel sheet columns into NSArray in iOS

ios,objective-c,csv,nsarray
I made few csv files by converting excel docs. Below code am using to read the csv file. I tried parse by index but it returning the row values instead of columns NSString *sourceFileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"GanditProState" ofType:@"csv"] encoding:NSUTF8StringEncoding error:nil]; NSMutableArray *csvArray = [[NSMutableArray alloc] init]; csvArray =...

NSArray filterArrayUsingPredicate never returning/ blocking execution

ios,objective-c,arrays,nsarray,nspredicate
I'm trying to filter an array of custom objects based on the name property of those objects. To make sure everything was working, I simply used this which should match with exactly 1 element in the array: NSLog(@"Length before %lu", (unsigned long) [self.mutableAvailableSources count]); NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(name ==...

separate future date in nsmutablearray

ios,objective-c,nsmutablearray,nsarray,nsdate
I am having a mutable array in that array i am having only past date, current date & future date. I have to separate the future date & store into another array. Can you help me. This is my array: uniqueItems( "2015-03-01", "2015-02-28", "2015-02-22", "2015-02-21", "2015-02-20", "2015-02-15", "2015-02-14", "2015-02-13", "2015-02-08",...

Sort NSArray to a particular sequence using an NSComparisonResult

ios,objective-c,nsarray,comparator
I'm trying to sort my arrays with a particular sequence using an NSComparisonResult. I'm unable to figure out how to achieve the sequence I'm wanting. I'm trying to weight Emojis towards the top (sequence of Emojis doesn't matter), followed by A-Z letters with giving a weight towards lowercase before uppercase,...

NsArray ContainsObject is not working with Custom NsObject Class

ios,objective-c,compare,nsarray,nsobject
I am checking if my one of the array consist the Nsobject which i have created custom way. i am using ContainsObject method.my problem is that contains object not working ever.even though i have same object in array its not returning the true value. if([self.arrSelectedInterest containsObject:interest_ent]) i am also attaching...

Sort NSMutableArray as threaded comments

ios,objective-c,uitableview,nsmutablearray,nsarray
I'm developing an iOS app for website, that uses disqus comment system. So I'm trying to add feature for adding comments from this application. My problem is that I don't know how to keep threaded structure, for example: Comment 1 Child 1.1 Child 1.1.1 Child 1.1.2 Child 1.2 Child 1.2.1...

Swift equivalent of arrayWIthObjects?

ios,objective-c,swift,nsarray
This is in Obj C: NSArray *arr = [NSArray arrayWithObjects:kLMEnglish,nil]; Can someone tell me the swift equivalent for this line of code....

Display an array of Parse PFGeoPoints as Map Annotations Error

ios,objective-c,parse.com,nsarray,mkannotation
I am attempting to display objects stored in a NSArray on a map. The objects are being pulled from a Parse.com class called Affiliates after a method to fetch locations within 2 miles of a user has been executed. I have used NSLog to confirm that the query is executing...

Objective-C get object item

objective-c,cocoa,nsarray
I am getting my object at index like so: NSLog(@"%@", [[dataSource cellHolder] objectAtIndex:69]); Now cellHolder has at index 69 an item called "Task" and I would like to get the value of "Task". How would I do that? Example: cellHolder[69]["Task"] == "Task 69"; trying to get that "Task 69" text....

NSArray with UI objects (Performance)

ios,objective-c,performance,uiwebview,nsarray
I have a NSArray (actually is a mutable array) with a UIWebView object in each index. I use this array to populate cell in a UITableView. I use a for loop to initialize each object in the array as following: for (int i = 0; i < [self.events count]; i++)...

Running an NSTimer for objects in an NSArray

ios,objective-c,timer,nsarray,nstimer
I have an NSArray of NSObjects. For each object in the NSArray, I'd like to run a timer until it finishes, then restart it for the next object. The objects in the NSArray will be used to populate UITextFields. I've tried for (NSObject *myThing in self.ArrayOfMyThings), it ends up displaying...

Set Images Randomly for buttons from array and take button's cgrect's from aray

ios,objective-c,nsarray
I have 42 buttons in my storyboard and I have take array of images. In this array there are total 7 images. NSArray *arrimg=[NSArray arrayWithObjects:@"book.png", @"lock.png", @"Exclamation.png", @"game.png", @"Music.png", @"Videos.png", @"Camera32.png", nil]; So how could I take random images every time on button? Should I take button collection or do...

parameter for NSString objects in NSArray

objective-c,parameters,nsarray
I'm writing a function that accepts an NSString objects that are stored in NSArray. However, I have no idea what kind of parameter must I use in my method declaration. Normally I would use NSString *parameter, but this time I need to use the index number of specified argument. The...

NSPredicate with NSDictionary, NSArray, JSON & HTML data

ios,objective-c,json,nsarray,nspredicate
I would like to fetch specific data in JSON data with NSPredicate. I don't know when I'm wrong, My NSLog arrayBDD works without NSPredicate... Here is my code : NSData *dataBDD = [NSData dataWithContentsOfURL:urlBDD]; NSDictionary *dicoBDD = [NSJSONSerialization JSONObjectWithData:dataBDD options:kNilOptions error:nil]; NSArray *arrayBDD = [[dicoBDD objectForKey:@"post"] objectForKey:@"content"]; NSLog(@"%@", arrayBDD); NSPredicate...

Trouble sorting custom objects in an NSArray numerically

ios,objective-c,arrays,sorting,nsarray
If I'm trying to sort BL_Player by their playerScore property: NSArray *sortedPlayers = [players sortedArrayUsingComparator: ^(BL_Player *a1, BL_Player *a2) { return [a1.playerScore compare:a2.playerScore options:NSNumericSearch]; OR NSArray *sortedPlayers = [players sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { NSInteger first = [(BL_Player *)a playerScore]; NSInteger second = [(BL_Player *)b playerScore]; return [first compare:second options:NSNumericSearch];...

How to compare various NSArrays in Objective-c?

ios,objective-c,nsarray
My code contains four NSArrays, each of which contains two objects which represent XY-Coordinate at any point on the screen. Two or more arrays may contain same set of coordinates. I need to find the coordinate which has highest number of repetition among these four arrays. Can the isEqualTo: method...

Objective-C Bridge NSArray Crash

objective-c,arrays,swift,nsarray
I'm trying to send some data from a swift file to an objective-c file. I have all the bridging headers and whatnot configured, such that when I pass a string, it can be used by the objective-c file. However, I would really like to pass an NSArray, and when I...

How to copy an array from a function to an array in the class in Swift?

arrays,xcode,swift,xcode6,nsarray
I have an array in a function. Look below. var HeadlinesString:NSString = Headlines["text"] as NSString var headlinesArray: NSArray = HeadlinesString.componentsSeparatedByString("\n") as NSArray I also have an empty array inside the class. Look below var headlinesLabels: NSArray = NSArray () I want to copy the headlinesArray to the headlinesLabels so I...

How to get specific strings from NSString?

ios,objective-c,search,nsstring,nsarray
I have a string such as: Sodium Nitrite E250 is a food additive that gives cured meats, such as ham E103, bacon, hot dogs, frankfurters, smoked fish E1255 corned beef, their characteristic red colour and flavour. I need to get an NSArray of elements: E250, E103, E1255 from text above...

NSArray? doesn't have member named “Generator”

ios,swift,nsarray
I am getting a weird error from this segment of the code: let path = NSBundle.mainBundle().pathForResource("SampleData", ofType: "plist") let dataArray = NSArray(contentsOfFile: path!) for dict: AnyObject in dataArray{ ...} ...

NSObject class conforms to protocol contained in NSArray with Swift

swift,nsarray,protocols,swift2,swift-array
I would like to create a method in Swift that returns an array of NSObject objects that conform to a protocol. I've tried something like this: func createManagers() -> [Manager] { let result = NSMutableArray(capacity: self.classes.count) (self.classes as NSArray).enumerateObjectsUsingBlock { (object: AnyObject!, idx: Int, stop: UnsafeMutablePointer<ObjCBool>) -> Void in //...

How to filter an array between 2 values using NSpredicate in objective c ? I want to filter an array via name or version

ios,iphone,nsarray,filtering,nspredicate
(void)filterListForSearchText:(NSString *)searchText { NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd]%@" ,searchText]; self.searchResults = [NSMutableArray arrayWithArray:[self.devices filteredArrayUsingPredicate:filterPredicate]]; [self.tableView reloadData]; } where self.device log is::: Array is, ( "<NSManagedObject: 0x7ffa32caab60> (entity: Device; id: 0xd000000000080000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD /Device/p2> ; data: {\n company = c1;\n name = apple;\n...

How to validate multi-dimentional NSArray structure?

ios,objective-c,validation,multidimensional-array,nsarray
Let's say we have NSArray of NSArrays of NSNumbers like this: NSArray *transform = @[ @[@1, @0, @1], @[@0.01f, @1, @0], @[@1, @0, @1.1f] ]; and we want to validate its structure against the rule "3x3 NSArray of NSNumber". The solution I've developed goes like this: BOOL __block validTransform =...

(SKNode) not convertible to string (it was working with old xCode)

ios,xcode,swift,nsarray,updates
In my apps I was using this piece of code and it worked perfectly: var data3: NSArray = [] //1 for gg in data3{ //2 var hh:String = gg["percentage"] as String //3 perchomerec = hh.toInt()! //4 } Now I updated my xCode and OSx version and now this same piece...

Searching an Array of Strings in Array of Dictionaries

ios,objective-c,nsarray,nsdictionary,nspredicate
I have an array of combinations which needs to be searched in another array of dictionaries Array Of Dictionaries is as follows: self.listOfAllContacts ({ name = "William"; recordId = 541; }, { name = "Soan"; recordId = 541; }, { name = "kamal"; recordId = 541; }, { name =...

How do you filter an NSArray with an Array of NSPredicates?

objective-c,cocoa,nsarray,nspredicate
I know you can do something like [..."SELF.some_id == [c] %d AND SELF.some_id == [c] %d", id1, id2], but I need more than this. Is there a way to do this without building a string. For example... NSArray *arrayOfWantedWidgetIds = @[1,3,5,6,9,13,14,16]; NSMutableArray *allWidgets = [[WidgetManager sharedWidget] getAllWidgets]; NSPredicate *predicate =...

Shuffle NSArray

ios8,nsarray
I got an NSMutableArray with a rather small number of objects that varies from 1 to max 20. When user taps a button I want to select one random object and display it. I've tried shuffling the array: srandom(time(NULL)); for (NSInteger x = 0; x < [array count]; x++) {...

What is the Implementation of: + (instancetype)array;

objective-c,nsarray
I'm curious to know what the actual implementation of the class method + (instancetype)array that is declared in NSArray.h would look like: NSArray.h + (instancetype)array; NSArray.m + (instancetype)array { // What goes here? } ...

NSMutableArray array isn't created

objective-c,nsarray
On line that is marked with a comment "RIGHT HERE" (the last if statement) compiler tells me "index 0 beyond bounds for empty array" which I interpret as - the array wasn't created. The idea is - in that last loop I'm going to sum up areas of already existing...

How to add and update the objects of two dimensional array in objective-c?

ios,objective-c,iphone,nsarray
I want to make a two dimensional array in objective-c and initialize all the indexes as zero. whenever my data (2D Coordinate) matches with any row/column then I want to upgrade the respective index by value one. So that later on I can scan for my highly probable coordinate on...

NSMutableArray showing “(” “)” normal brackets instead of “[” “]” square bracket in NSLog

ios,objective-c,nsmutablearray,nsarray
Iam trying to send one json in POST request. I created one NSMutableDictionary and added Key Value pairs, i have one NSMutableArray which contains Binary Stream of UIImage. so When i Add this NSMutableArray into NSMutableDictionary and i did one NSLog So result is { key:value, key:value1, ArrayKey:( iuhdgbdsnb325435435j435bu4h5h45hu34h545ih43h5i43hi5hu3i4h5u3 )...

Accessing Properties of Objects in Array

objective-c,nsarray
I'm pretty new to programming, and am a little caught up in what to do. Now, each of the objects in my NSArray has its own properties containing data in which I need. I'm used to iterating through an array to access it's objects, but have never had to iterate...

Passing String array to a function

ios,swift,nsarray
I am trying to pass an array to a function: var array:[String] = [] // fill the array array.append(uniqueId as String) // pass the array to a function: GamePrefrences.setLevelsArray(array) My function is declares like this: func setLevelsArray(arr:[String]) { GamePrefrences.levels_array = arr } But on the line i try to call...

exception in NSArrayM insertObject:atindex

ios,nsarray
i have used 4 images in project ..while running it results in: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: my code : NSArray *imageNames= @[@"jake_2.png",@"jake_3.png",@"jake_4.png",@"jake_5.png "]; // Do any additional setup after loading the view, typically...

iOS: remove objects or reinitialize arrays in swift?

ios,swift,nsmutablearray,nsarray
I'm new in swift and I want to know if the beast approach to reuse an array is to delete all object inside or reinitialize it. For example if I have: var my_array:NSMutableArray! //global variable and the first method that I use: func firstMethod{ my_array = NSMutableArray() my_array.addObject("one") my_array.addObject("two") my_array.addObject("three")...

Turning objects filtered from managedObjectContext into an NSArray

swift,core-data,nsarray,nsmanagedobject,ios8.1
I'm relatively new to iOS and I find myself "thrown to the wolves" on a Core Data assignment. I'm trying to create an array of Note objects using a NSPredicate to search a managedObjectContext. It's not working, but I think I'm close to the "finish line". Here's what I've got:...

Parsing objects in Json array as a dictionary Swift

ios,json,swift,nsarray
So I have JSON data that is formatted as a list of dictionaries, and I have it stored as an NSArray Object, but I'm unsure how to convert each entry into a dictionary object when it is currently AnyObject The AnyObject data is already formatted like a JSON dictionary Here...

Check if array contains part of a string in Swift?

arrays,swift,nsarray
I have an array containing a number of strings. I have used contains() (see below) to check if a certain string exists in the array however I would like to check if part of a string is in the array? itemsArray = ["Google, Goodbye, Go, Hello"] searchToSearch = "go" if...

NSArray key => value,

ios,objective-c,nsarray
My key value current system isn't working. Here where the array is set. NSArray *matchInfo = [[NSArray alloc] initWithObjects: @{@"matchName" : _matchName}, @{@"hostName" : _hostName}, nil]; Then is it converted into NSData NSData *dataToSend = [NSKeyedArchiver archivedDataWithRootObject:message]; Received and set NSArray *receivedArray = [NSKeyedUnarchiver unarchiveObjectWithData:receivedData]; _matchName = [receivedArray valueForKey:@"matchName"]; _hostName...

set NSArray protocol in swift

ios,objective-c,swift,nsarray,protocols
In Objective-C you can do something like NSArray<ReviewC>* reviews; in order to make a variable NSArray which follows the protocol ReviewC, I need to do the same in Swift, I need to make NSArray follow a protocol, it has to be An NSArray, not an Array. I know I can...

Sort NSArray for a specific order

iphone,sorting,ios7,nsarray
I have an NSArray of custom objects. Each object contains one integer value for ex. 1,2,3,4 Now I want to sort Array like below 9 7 5 3 1 2 4 6 8 Could some one help me?...

How to get a specific object from data structure based on Index

ios,objective-c,nsarray,nsdictionary
I am creating a custom UIPageViewController which uses a custom setup. The data structure that I have is parsed into the following format: { "1.0" = ( { detail = "Detail 0"; icon = "Pull to Refresh"; title = "Item 0"; }, { detail = "More easily refresh a subscription...

Parsing a Dictionary of Arrays from a Plist file

ios,objective-c,nsarray,nsdictionary
I am trying to work with a specific data layout. We use a plist file which is setup in the following way: Root (Dictionary): - 1.1 (Array) -- Item 0 (Dictionary) --- Title --- Icon -- Item 1 (Dictionary) --- Title --- Icon - 1.2 (Array) -- Item 0 (Dictionary)...

Getting error related to NSDictionary object type

ios,objective-c,nsarray,nsdictionary,nspredicate
I want to filter list of countries based on either Country name or Country ISD code. For example, if user types '9', India should be added to filtered array because ISD code of India is "+91". My datasource contains all the information like country name, ISD code etc.. Here is...

split NSString into NSArray in ios

ios,objective-c,nsstring,nsarray
i'm trying to split NSString to NSArray.String like this: @"text,image". And I am splitting it like this: arrayAnsType = [self.strAnsType componentsSeparatedByString:@","]; NSLog(@"Terms array %@",arrayAnsType); But output like this: ( "(\n \"text", "image\"\n)" ) ...

Compare two arrays of dictionaries and add/remove items

ios,objective-c,nsarray,nsdictionary
I have two arrays of dictionaries like this arrCurrent = [{ id = 1; name = "Name1"; },{ id = 2; name = "Name2"; },{ id = 3; name = "Name3"; }]; arrUpdated = [{ id = 1; name = "Name1 has changed"; },{ id = 2; name = "Name2...

NSMutableArray adds same NSDictionary multiple times

ios,objective-c,for-loop,nsarray,nsdictionary
I am looping through an array, getting two items and putting them in a dictionary, and then add them to an array, but it keeps adding the last item of the array for the number objects in the array, even though when I log the dictionary inside the loop it...

Can't remove all objects in NSMutableArray

ios,objective-c,nsmutablearray,nsarray
For some reason, I keep getting this error when I run my app: [__NSArrayI removeAllObjects]: unrecognized selector sent to instance I set up the NSMutableArray in .m like this: @implementation ChooseViewController { NSMutableArray *trackName; } And populate it like this: trackName = [JSON valueForKeyPath:@"results.trackName"]; But when I run this code,...

are 2 array objects equal?

objective-c,nsarray
I'm trying to find if paket2 contains any object from paket1. I tried this code: //assume paket1 and paket2 are 2 NSArrays int n; int m; for (n=0; n<[paket1 count]; n++) { for (m=0; m<[paket2 count]; m++) { if (paket1[n]==paket2[m] ) { NSLog(@"some message"); }else{ NSLog(@"bruhuhuhu"); } } } but...

NSPredicate with bitmask for filtering NSArray

ios,objective-c,nsarray,nspredicate,photokit
I'm trying to test whether some particular asset collections contain only one media type/subtype using an NSPredicate. The: testForPhotosPredicate works just fine, however when trying to use the testForPanoramasPredicate it fails with the message: Unable to parse the format string "mediaSubtypes & %i" How can I use a bitmask in...

Checking array indexes when using literal subscripting

objective-c,cocoa,cocoa-touch,nsarray
As Apple suggests, we need to check the index of an NSArray before calling objectAtIndex:. To do this, we can use a category or method swizzling. For this subscript syntax, index = 1; id person = pArray[index]; is there a way to implement that? Of course, I can check index...

Swift: An NSArray for some reason is being read as AnyObject

ios,objective-c,swift,nsarray
I am trying access an NSArray like so. func stackedViewDidAlign (stackedView : PSStackedViewController) { stackedView.viewControllers.objectAtIndex(0) } However, it says AnyObject does not have a member named 'objectAtIndex' This is what viewControllers from PSSTackedViewController class looks like. @property(nonatomic, readonly, strong) NSArray *viewControllers; I am not sure what is going on and...

IOS conpare two NSArrays

objective-c,nsarray
I have 2 arrays, Array1: I have 3 object, 1 object have 3 information: (ID, Username, password) Array2: I have 2 object, 1 object have 4 information: (ID, Contact, NumberPhone, Email). value of ID in 2 array is same. I want compare Array1 with Array2 according ID. if Array1 have...

array not sorting on device - works in Simulator

ios,sorting,nsarray
I've been trying to fix this but I haven't been able to do it so far... in my device my array isn't shown ordered, while on the Simulator it is... in these lines I sort / assign / reload my view. self.appDelegate.listaEventos = [tempArray sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { NSDate...

Get NSString as NSArray from NSDictionary

ios,objective-c,iphone,nsarray,nsdictionary
I've the following data in NSDictionary for an object field_names that has below value. {dBur0z9,nr8r0,R0ru,jrurw,qB5rz9ry},{gr2,Z5uzr,Rwxyr5z0Ar5},^~gr2~cry69v~br9rtyz~Z03r4rsru^~Z5uzr~Uvy3z~dB4srz^5B33,(),9ruI,evD3rsv3,,HLK,evDsBAA65,evDtyvt2s6E,5B33,5B33,5B33,5B33,{6ww},SRiTfUV,5B33,5B33,5B33,5B33 I'm trying to get it as NSArray. I tried `NSArray *array = [dictionary objectForKey:@"field_name"]; But that returns an NSString not an NSArray. Then I tried to replace { } with [ ] and appended [...

NSArray alloc and init

ios,objective-c,nsarray
I'm a little confused about NSArray initialization. The confusing thing is we have different init methods to init it, and if I just init it without giving any size and any objects, how compiler knows it object count or size in RAM. What's the logic/difference behind init method? Can anybody...

Check wether a specific place in NSArray is nil

ios,objective-c,arrays,null,nsarray
I'm trying to check if a place in my array is nil like so: if (resultArray[1] == nil) { NSLog(@"..."); } But it always crashes with the message: [_PFArray objectAtIndex:]: index (1) beyond bounds (1)' How can I fix this, or is there any other way to check it? Thanks!...

enumerateObjectsUsingBlock - casting parameters in Swift

ios,swift,nsarray
I want to refer to enumerated objects with their specific type, instead of just a generic AnyObject!, but cannot find any information about it in the docs. The signature of enumerateObjectsUsingBlock in Swift is: func enumerateObjectsUsingBlock(_ block: ((AnyObject!, Int, UnsafePointer<ObjCBool>) -> Void)!) and in Objective C: - (void)enumerateObjectsUsingBlock:(void (^)(id obj,...

Read NSArray of CGPoints in Swift

ios,objective-c,swift,nsarray
I have a function in an Objective-C class that returns an NSArray: - (NSArray *) myAwesomeFunction { // Good stuff here return array } Now I know that the members of this array are all NSValue objects with a CGPoint inside. This information is not available to Swift however, which...

Incompatible block pointer type? Cannot return NSArray

objective-c,nsarray,objective-c-blocks
I have a block we return an array in callback. Then I create another method to store that array as below: - (NSArray *)getUserData{ [self fetchDataByUserId:self.userID completionHandler:^(NSArray *record) { return record; }]; } I received this kind of error so please help me, I don't understand. "Incompatible block pointer types...

Get rid of mistaken peaks in an iOS graph

ios,objective-c,graph,nsarray,smoothing
I have a NSArray of float values, and I represent this array in a graph, it looks this way: As you see, there are peak values...I can easily count them when I look at the graph (11 peaks), but if I look at my array values, there are some "false"...

How to iterate concisely through @properties on an NSObject subclass to set properties from a plist?

cocoa,nsarray,nsdictionary,plist,nsobject
Say I have a subclass of NSObject (let's call it 'BSObject') with the following properties: NSString *name; NSNumber *num; I have an NSMutableArray of BSObjects (let's call that one 'BSCollection'). For storage on disk, I have a property list which is an array of dictionaries. The BSCollection is represented by...

Error : Command failed due to signal : Segmentation fault: 11

swift,nsarray,xcode6.1.1
I am trying to get an array from dictionary, but I am getting an error for below line self.items = self.dataDictionary["geoNames"] as NSArray Complete code is as below var dataDictionary: AnyObject! var items: NSArray! override func viewDidLoad() { super.viewDidLoad() var url = NSURL(string: "http://api.geonames.org/countryInfoJSON?username=temp") var urlRequest = NSURLRequest(URL: url!) NSURLConnection.sendAsynchronousRequest(urlRequest,...

Convert NSArray to Swift Array and filter out Elements not matching T

ios,objective-c,casting,nsarray
Converting NSArray to a Swift Array of Type T is easy, if all the elements are indeed of type T already: let arr1 : NSArray = [1,2,3] let arr2 = arr1 as? Array<Int> // works But now assume a non-homogenous NSArray with objects that do not match T: let arr1...

Parsing JSON into a usable format

swift,nsarray,nsdictionary,nsurl
I'm currently downloading data from a server and I'm not sure how to get the response that I'm getting back into the format that's expected by the method that I'm working with. Could someone guide me on what I would need to do to get all of the items in...

Convert this to javascript

javascript,json,swift,nsarray,nsdictionary
I have some Swift code that needs to be written in javascript. I am not sure how to do this. jsonresult is the json data. Can anyone help? let results: NSDictionary = jsonresult["results"] as! NSDictionary let collection1: NSArray = results["collection1"] as! NSArray for item in collection1 { Thanks...

What is the best way to convert an array with NSStrings to NSDecimalNumber?

ios,objective-c,nsstring,nsarray,nsdecimalnumber
I have an NSArray with 10 NSStrings inside: myArray ( @"21.32", @"658.47", @"87.32"... ) What's the best way to convert all the strings to an NSDecimalNumber?...

Extract the extension and save image names in array

ios,arrays,nsarray
I have few images in the "ProjectImages" folder and wanted to retrieve the image file name from the above folder and store it in array and then i wanted to extract the extension of those images files and store it in another array. I'm able to retrieve the image file...

How compare the user actual time with a NSArray?

objective-c,nsarray,nsdate,nstimer,nstimeinterval
I have a NSArray with many different hours as NSStrings. My question is, how can I compare the actual time of the user with the values into the NSArray and get which is the next hour to the actual user? For example, if the NSArray has got @"07:00", @"07:30", @"08:00",...

Convert NSDictionary to NSArray

ios,objective-c,uitableview,nsarray,nsdictionary
I'm trying to convert my NSDictionary (storageData) to an NSArray, as I need to pass the data (title) contained in the dictionary through a segue. I've implemented the below (see last method, the tableview is simply to provide some context), but a crash occurs with the following error: Terminating app...

Swift NSArray subscript a value of type AnyObject

ios,swift,nsarray
This my my NSArray var RidesData:NSArray = [] It is used to store an JSON Array i have converted RidesData = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as! NSArray Sample of the Array Optional(( { ContentType = USSShow; Name = "Lake Hollywood Spectacular\U00ae (Seasonal Show)"; NextShowTime = "8:00pm"; NextTimeSlot = "";...

iOS:Placing NSArray in NSString

ios,objective-c,arrays,nsstring,nsarray
I am doing application related to sending data to server and I had array of values and when I am printing that array I getting the out put as below for the code NSArray *dataarray=[NSArray arrayWithObjects:@"2",@"10",@"1",@"4",@"2",@"8",@"2",@"6",@"25",@"11",@"17",@"10",nil]; NSMutableArray *arr=[[NSMutableArray alloc]init]; for (int i=0; i<[dataarray count]; i++) { NSString *stringvar=[dataarray objectAtIndex:i]; NSDictionary...