nsdictionary

How to save (and retrieve) NSAttributedString in a NSDictionary

感情迁移 提交于 2019-12-06 11:30:42
I am trying to save and retrieve XML data to a file. For this purpose I am using NSDictionary 's writeToFile: The question is, how to write and retrieve an attributed string to and from a file on disk using NSDictionary 's writeToFile: ? NSAttributedString is not a property list object , so writeToFile: won't work. It does, however, conform to NSCoding , so you can write it to an archive with your dictionary as the root object (assuming that all the other objects in the dictionary also conform). If you need something more portable than archived object consider using RTF representation of

NSDictionaryController doesn't seem to observe changes to content dictionary

烂漫一生 提交于 2019-12-06 10:41:49
问题 I must be missing something simple, but I am having some trouble binding a tableView to an NSDictionaryController. Here is a model of my current scheme: TableViewColumn --bindsTo-->DictionaryController.arrangedObjects.(value or key) --bindsTo-->someClass.someClassMember.aDictionary. I've tested the tableView by adding an entry to aDictionary on init, which is displayed correctly. But when another method produces an object that is then added to aDictionary, the TableView doesn't seem to update

NSDictionary read data

本秂侑毒 提交于 2019-12-06 09:58:35
问题 I have now tried to get this to work for a few hours but just cannot get it right. I have the following code: NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSArray arrayWithObjects:@"currentGame1", @"currentGameType1", @"currentGameQuestion1", @"currentGameRightAnswers1", @"currentGameType1", @"numberOfType0Games1", @"type0Results1", @"numberOfType1Games1", @"type1Results1",@"numberOfType2Games1", @"type2Results1",nil], @"Player1", [NSArray arrayWithObjects:@"currentGame2"

ObjC to Swift conversion of NSDictionary to NSObject : AnyObject

半城伤御伤魂 提交于 2019-12-06 09:50:56
问题 I'm implementing Segment.com's iOS library with Swift and all is working great, just stuck on the code conversion below of the identify method: ref: https://segment.com/docs/libraries/ios/#identify [[SEGAnalytics sharedAnalytics] identify:@"userId" traits:@{ @"email": @"em@il.com" }]; where traits is an NSDictionary *, optional Xcode tells me (typeahead hints) that in Swift it translates to: SEGAnalytics.sharedAnalytics().identify(userId: String!, traits: [NSObject : AnyObject]!) As a new

How to display image from a RSS feed

梦想与她 提交于 2019-12-06 08:52:14
I'm trying to build an app that shows the latest RSS feeds from http://news.yahoo.com/rss/ I'm able to parse the xml using NSXMLParserDelegate, I'm able to show the date and time along with the title for the particular feed, but I also want to display an image for every feed, I know how to parse the main elements but I dont know how to pass the attributes for a child element which has a url as its key... e.g. the above feed consists of the following: <item> <title>fooo</title> <description ahref="some link" image src="http://l1.yimg.com/bt/api/res/1.2/Wo3_apH.kz7DMvOj7MDtRQ--

Parse Query String into a Structured NSDictionary

岁酱吖の 提交于 2019-12-06 06:58:41
I have a query string: a=1&b=2&c[1]=3&c[2]=4 etc… I want a NSDictionary where a => 1 , b => 2, c => [3,4] . Notice that that the value for c is an array. It should also be able to handle something like c[1][2]=5 to make an array of arrays c => [[5]] . Of course I can do it myself by splitting on the & and = , but what about other cases such as arrays and arrays of arrays. I want a structured NSDictionary from a POST request queryString and do not want to rewrite the wheel if this already exists. Are there any class/method, through Apple or 3rd party, that will parse a query string into a

Could you help me to understand block types when added to containers (NSDictionary, NSArray)?

独自空忆成欢 提交于 2019-12-06 06:47:04
Normally blocks can be of 3 types: NSGlobalBlock, NSStackBlock, NSMallocBlock. Lets take the following example: void (^aBlock)(NSString *someString) = ^(NSString *someString){ NSLog(@"Block was executed. %@", someString); }; NSDictionary *dictionary = [NSDictionary dictionaryWithObject:aBlock forKey:@"aBlock"]; Because aBlock doesn't capture surrounding scope if I do po dictionary I get aBlock = < NSGlobalBlock :0x165dde60> and this is correct If I then do a: NSString *string = @"Test"; void (^aBlock)(NSString *someString) = ^(NSString *someString){ NSLog(@"Block was executed. %@ %@",

Split NSArray into sub-arrays based on NSDictionary key values

谁都会走 提交于 2019-12-06 05:46:33
问题 We have an app that calls a SOAP web service and retrieves a long list of XML, which the app then parses into an NSArray of NSDictionary objects. The NSArray contains a list of Rental Apartment information, each of which is stored into an NSDictionary . The entire list may contain 10 different types of Apartments (i.e. 2-room, 3-room), and we need to split the NSArray into smaller NSArray s based on Room-Type, which has the key "roomType" in the NSDictionary objects. Currently our algorithm

Sort NSArray of NSDictionaries using comparator

为君一笑 提交于 2019-12-06 05:46:12
I've been trying to sort an NSArray of NSDictionaries using a comparator, but I cannot seem to get the output I desire. The output I'm trying to achieve is that A-Z usernames should come first in the sorted array, then usernames that start with a digit should come second in the sorted array, and lastly usernames that start with an underscore should be last in the sorted array. Any help is truly appreciated! EDIT: It should be sorted so it looks consistent through the whole NSArray so that: _Anna comes before _Bob and _11Bob comes before _12Cary but after _09Bob Example of desired output I'm

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