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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:15:14+00:00 2026-05-26T21:15:14+00:00

Shortly: how to determine if id is CFType or not at runtime i’m implementing

  • 0

Shortly: how to determine if id is CFType or not at runtime

i’m implementing dynamic core data attributes and in willSave method of ExtendedManagedObject i wanna check if the id value is CFType to store it into plist file.

If I’m trying to save to plist UIImage, that is not toll-free bridged with CF (apple docs), I am getting an error:

2011-11-17 17:16:25.294 [490:707] Error saving extended data: Property list invalid for format (property lists cannot contain objects of type ‘CFType’)

Can I check it with some method or I have to implement by myself (just isKindOfClass from docs)?

I don’t want to implement accessors in NSManagedObject subclass, I dont know exactly how many urls I’ll get from entities properties. Question is about dynamic extended attributes at runtime.

- (void)willSave
{
NSDictionary *changes = [self valueForKey:@"extendedChanges"];
if (changes!=nil) {
    // merge changes into snapshot
    NSMutableDictionary *dict = [[self extendedSnapshot] mutableCopy];
    NSEnumerator *e = [changes keyEnumerator];
    NSString *key;
    while (key=[e nextObject]) {
        id value = [changes objectForKey:key];



        if (value==[NSNull null])
            [dict removeObjectForKey:key];
        else if (#ugly and I'm not shure is thread safe **else if ([value isKindOfClass:[NSArray class]] || [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSDate class]] || [value isKindOfClass:[NSData class]] || [value isKindOfClass:[NSString class]] || [value isKindOfClass:[NSNumber class]])**)
            [dict setObject:value forKey:key];
    }

    // archive as binary plist
    NSData *data = nil;
    if ([dict count]>0) {
        NSString *error=nil;
        data = [NSPropertyListSerialization dataFromPropertyList:dict 
                                                          format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error];
        if (error!=nil) {
            NSLog(@"Error saving extended data: %@", error);
            [error release];
        }
    }
    [dict release];
    [self setPrimitiveValue:data forKey:@"extendedData"];
}
[super willSave];
}
  • 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-26T21:15:15+00:00Added an answer on May 26, 2026 at 9:15 pm

    That’s a wrong way to approach the problem. The blog post you referenced saves the extended attributes as a serialized plist. The plist can contain only the following types of objects, as written in the official doc:

    NSArray, NSDictionary, NSDate, NSData, NSString and NSNumber.

    Other classes are just not allowed. Don’t add objects of any other class to the attributes extended this way.

    Also, saving an image file in a CoreData database is not a good idea, generally speaking, read On Blobs in the official doc. Instead, save the UIImage in a file and write the file path in the CoreData database.


    If you just have a transient property which is not saved to the database, you don’t even have to go through the trouble of creating extended attributes. Just add it as a property of a subclass of NSManagedObject:

    @interface MyManagedObject: NSManagedObject {
    }
    @property(retain, nonatomic) UIImage* thumbnail;
    @property(retain, nonatomic) NSDictionary* thumbnailDictionary;
    @end
    

    without adding thumbnail in the CoreData model. Then do the corresponding @synthesize in the .m file. The property added this way to a managed object is just not saved.

    If you want to keep unknown number of thumbnails, you can put an NSDictionary (or NSArray) containing UIImage*s.


    If you really do want to get CFType from an NSObject*, do the following:

    NSObject* x= ...;
    CFTypeID typeID=CFGetTypeID((CFTypeRef)x);
    if(typeID != CFStringGetTypeID() &&
       typeID != CFDateGetTypeID() &&
       typeID != CFDataGetTypeID() &&
       typeID != CFDictionaryGetTypeID() &&
       typeID != CFArrayGetTypeID()  ) {
           ... it's a non-plistable type ...
    }
    

    The ugly if clause is there because there’s no public function which gives you the CFTypeID of an un-bridged Objective-C object.
    Read CFType reference. But I don’t recommend doing this.

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

Sidebar

Related Questions

I know how to store data in MySQL. Shortly, I know the basics: design,
Shortly after I installed MS SQL Server 2008 on my machine, I forgot the
This is my problem - shortly: var c1:TClass1; c2:TClass2; begin c1 := c1.Create; c2
I am shortly starting a project, which requires messages to be held in a
I'll try to explain shortly what I want to do: A project using a
Python 3.0 is in beta with a final release coming shortly. Obviously it will
Okay, I will shortly be starting down the path of windows mobile development. I
I have a small project that I will be working on shortly that collects
Our system (exotic commodity derivative trade capture and risk management) is being redeveloped shortly.
I just recently noticed this behaviour. To put it shortly, it displays the commits

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.