Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3490958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:34:44+00:00 2026-05-18T11:34:44+00:00

I’m trying to create a semi-complex set of view animations (think an animated version

  • 0

I’m trying to create a semi-complex set of view animations (think an animated version of an NSMatrix form, where rows slide around as other rows are added or removed), and to build the animation I’m making a little helper class.

There I have to keep track of the different views, their ordered indices, and few some other values associated with their animations.

To that end, I’m using an NSArray instance to keep track of the ordering (indices) of the views, and I’d like to use an NSDictionary with the views as keys to keep track of the values (the values themselves are in nested dictionaries). I.e. I’d like to be able to do something this, for instance (pseudo code):

NSMutableDictionary* viewValuesDict = [NSDictionary dictionary];

// Loop thru an ordered NSArray
for( (NSView*) view in viewsArray ) {
    // Get some values we'll need later
    NSDictionary* associatedValues = [view getSomeValues];

    // ...and put them into viewValuesDict...
    [viewValuesDict setObject:associatedValues forKey:view];

    // and then things break because the NSView 'view'
    // doesn't support copyWithZone.... darn
}

Problem is, I of course can’t use NSView instances as dictionary keys, because the keys are added using copyWithZone, which NSView does not implement.

So, what’s a good way to get a unique key for an NSView instance? I could conceivably use [obj description] since the memory address you get back is a perfect UID, but of course the system has to work with any kind of NSView subclass that might return something else entirely, so that’s no good.

Or should I maybe try something else entirely? Is there maybe some alternative to NSDictionary, where keys just aren’t copied? Because in this case I really have no need for the keys to ever be copied.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:34:44+00:00Added an answer on May 18, 2026 at 11:34 am

    Sometimes there are occasions where you want to use a view (whether NS or UI) as the key in a dictionary. I’ve come across one such situation. I would’ve preferred to use objc_setAssociatedObject, but that requires Snow Leopard. Boxing with NSValue will work, but if you need to be doing lots and lots of look ups given a view, the continual boxing and unboxing of pointers may become tedious.

    There are two options to creating an NSView => <object> dictionary.

    1. Use NSMapTable
    2. Use CFMutableDictionaryRef

    NSMapTable is a class introduced in 10.5 that is very similar to an NSMutableDictionary, except that it has extra abilities that make it work more nicely with garbage collection. In your case, you’ll probably want a map table with “weak” keys and “strong” values, but read the documentation for all the fun details.

    CFMutableDictionaryRef is the Core Foundation equivalent of an NSDictionary (they are toll-free bridged), but it has some extra creation options. You create one using CFDictionaryCreateMutable(), and that wants two struct parameters. One is a structure that defines the memory management (and other) behavior of how to deal with the keys of the dictionary, and the other is a struct for defining the behavior of the values. You can create a CFMutableDictionaryRef with the options of retaining the keys (instead of copying them) and then retaining the values. Once you’ve done this, you can cast the CFMutableDictionaryRef to an NSMutableDictionary and use it as you’d expect, just that the keys will be retained instead of copied.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.