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 7637043

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:50:30+00:00 2026-05-31T07:50:30+00:00

For attributes of struct types that NSKeyValueCoding can handle, I use the Core Data

  • 0

For attributes of struct types that NSKeyValueCoding can handle, I use the Core Data accessor pattern described in Apple’s docs here.

For example, an NSRange struct can be specified in the Core Data model as of type Transformable, then the NSValue rigmarole can be avoided for clients by providing accessors in an NSManagedObject subclass of the form:

Interface:

@property(assign, nonatomic) NSRange range;

Implementation;

- (NSRange) range {

    [self willAccessValueForKey:@"range"];
    NSRange retVal = range;
    [self didAccessValueForKey:@"range"];

    return retVal;
}

- (void)setRange:(NSRange)aRange {

    [self willChangeValueForKey:@"range"];
    range = aRange;
    [self didChangeValueForKey:@"range"];
}

Mogenerator’s generated NSManagedObject subclasses, however, declare Transformable attributes as NSObject properties, so clients need to get/set NSValues.

What’s the best way to handle this situation with mogenerator, whilst (1) keeping with the simple Transformable pattern rather than messing with transient backing attributes, and (2) avoiding any edits of Mogenerator’s ‘machine’ classes?

  • 0 0 Answers
  • 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-31T07:50:32+00:00Added an answer on May 31, 2026 at 7:50 am

    The ultimate way to deal with this would be, as scc suggested in the previously accepted answer, to change the mogenerator template files. They would need to (a) change the transformable attribute’s accessor to be of the appropriate type (NSRange in this instance) and then (b) add the accessors with the appropriate KVO method calls.

    As that’s more than I have time right now to figure out how to do, my temporary expedient is as follows:

    • add an attributeValueClassName key to the attribute’s userInfo dict (in the Core Data editor), with the value NSValue (just to make sure the generator’s accessors will be NSValue rather than NSObject).
    • in the human-editable mogenerator output, add accessors like those in the question, except with a new name (eg. rangeValue and setRangeValue). The underlying values will still be the persisted NSValues, but my accessors take care of the KVO and boxing/unboxing.

    Not ideal, but I do get strongly-typed accessors without having to edit the mogenerator machine files.

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

Sidebar

Related Questions

I have 2 attributes that I use within the controllers of my MVC application.
I have a struct that implements IValidatableObject, which I use for properties on a
I just want to parse some data that can be present in one of
I have an array of objects that have QTTime structs as attributes. The objects
Castle Validator uses attributes to specify validation rules. How can you hook these up
MVC use action attributes to map the same view for http get or post:
How can we apply attributes to class function using AOP in C#? UPDATE: I
I have a small XML file: <wddxPacket version='1.0'> <header/> <data> <struct type='coldfusion.runtime.ArgumentCollection'> <var name='HEADLINE'>
I need to write a file format that writes out data to a file
When I do #!/usr/bin/perl -w use strict; use Net::LDAP; use Data::Dumper; my $dn=...; my

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.