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 619691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:40:58+00:00 2026-05-13T18:40:58+00:00

In the 3.1 SDk, Apple added support for associated objects. However, the simulator will

  • 0

In the 3.1 SDk, Apple added support for associated objects.

However, the simulator will not compile code that includes references to objc_setAssociatedObject, objc_getAssociatedObject, et al. (Undeclared errors)

Is there away around this? Can I make the iPhone simulator compile this code? I would hate to have to do all testing on the device.


Update

Bug Filed:
rdar://7477326

  • 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-13T18:40:58+00:00Added an answer on May 13, 2026 at 6:40 pm

    A quick and dirty workaround (largely untested, may be buggy):

    #if TARGET_IPHONE_SIMULATOR
    
    #import <objc/runtime.h>
    
    enum {
        OBJC_ASSOCIATION_ASSIGN = 0,
        OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1,
        OBJC_ASSOCIATION_COPY_NONATOMIC = 3,
        OBJC_ASSOCIATION_RETAIN = 01401,
        OBJC_ASSOCIATION_COPY = 01403
    };
    typedef uintptr_t objc_AssociationPolicy;
    
    @implementation NSObject (OTAssociatedObjectsSimulator)
    
    static CFMutableDictionaryRef theDictionaries = nil;
    
    static void Swizzle(Class c, SEL orig, SEL new) // swizzling by Mike Ash
    {
        Method origMethod = class_getInstanceMethod(c, orig);
        Method newMethod = class_getInstanceMethod(c, new);
        if (class_addMethod(c, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
            class_replaceMethod(c, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
        else
            method_exchangeImplementations(origMethod, newMethod);
    }
    
    - (NSMutableDictionary *)otAssociatedObjectsDictionary
    {
        if (!theDictionaries)
        {
            theDictionaries = CFDictionaryCreateMutable(NULL, 0, NULL, &kCFTypeDictionaryValueCallBacks);
            Swizzle([NSObject class], @selector(dealloc), @selector(otAssociatedObjectSimulatorDealloc));
        }
    
        NSMutableDictionary *dictionary = (id)CFDictionaryGetValue(theDictionaries, self);
        if (!dictionary)
        {
            dictionary = [NSMutableDictionary dictionary];
            CFDictionaryAddValue(theDictionaries, self, dictionary);
        }
    
        return dictionary;
    }
    
    - (void)otAssociatedObjectSimulatorDealloc
    {
        CFDictionaryRemoveValue(theDictionaries, self);
        [self otAssociatedObjectSimulatorDealloc];
    }
    
    @end
    
    void objc_setAssociatedObject(id object, void *key, id value, objc_AssociationPolicy policy)
    {
        NSCAssert(policy == OBJC_ASSOCIATION_RETAIN_NONATOMIC, @"Only OBJC_ASSOCIATION_RETAIN_NONATOMIC supported");
    
        [[object otAssociatedObjectsDictionary] setObject:value forKey:[NSValue valueWithPointer:key]];
    }
    
    id objc_getAssociatedObject(id object, void *key)
    {
        return [[object otAssociatedObjectsDictionary] objectForKey:[NSValue valueWithPointer:key]];
    }
    
    void objc_removeAssociatedObjects(id object)
    {
        [[object otAssociatedObjectsDictionary] removeAllObjects];
    }
    
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
The SDK only said the null will returned if the image data could not
Using the latest SDK from Apple, I noticed that while running on the iPhone
I am looking at the 'Metronome' sample code from the iOS SDK ( http://developer.apple.com/library/ios/#samplecode/Metronome/Introduction/Intro.html
I was not able to find on Apple iOS SDK information regarding which directories
Apple annonced Shake API in iPhone SDK 3.0. I can not find any information
As many people are complaining it seems that in the Apple SDK for the
I am nearly sure, that i have seen a method (provided by the Apple-SDK)
Randomly im getting the following error from xcodebuild (iOS 5.0 SDK - Apple LLVM
I just installed the latest SDK from Apple so I can start learning iPhone

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.