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

  • Home
  • SEARCH
  • 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 6737105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:12:33+00:00 2026-05-26T11:12:33+00:00

I’m developing a Core Data app that uses a model object called Location. The

  • 0

I’m developing a Core Data app that uses a model object called Location. The user can enter locations and provide their latitude and longitude in decimal format. I use plain NSTextFields for this. As a feedback to the user, also their degrees/minutes/seconds counterparts are shown (using a label). The logic for transforming from decimal format to degrees etc. is implemented with the Location model object, which is a subclass of NSManagedObject.

Ideally I want to implement these as read-only attributes and have them tied in some way to their decimal counterpart, so that when the user changes the decimal representation, the degrees/minutes/seconds representation gets updated as well.

I’ve tried the following:

  • Set the controller as an NSTextFieldDelegate to intercept edits but this only works if the user actually edits the fields. This fails when the user accepts 0 as defaults for both latitude and longitude, which is actually a valid location.
  • I’ve looked at transient attributes for Core Data but found the documentation on this point not very helpful, although they might be the answer for this…

Any ideas on how to approach this?

EDIT:

As suggested by Francis McGrew, I implemented the following class method for Location:

+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
    NSSet *result = [super keyPathsForValuesAffectingValueForKey:key];

    if ([key isEqualToString:@"latitudeToDegrees"] || [key isEqualToString:@"longitudeToDegrees"]) {
        result = [result setByAddingObjectsFromSet:[NSSet setWithObjects: @"latitude", @"longitude", nil]];
    }
    return result;
}

Slightly different from his answer, as the DMS is just one attribute represented as a formatted String, calculated by Location. I then added bindings in the UI to latitudeToDegrees and longitudeToDegrees and …boom!.., a nicely updated UI.

  • 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-26T11:12:34+00:00Added an answer on May 26, 2026 at 11:12 am

    If someone could explain transient properties to me I’d love to hear it as well.

    Since DMS is easily calculated from the latitude and longitude, there’s no real reason to store those values as attributes in your model. I would just write methods that calculate and return the current degrees, minutes and seconds based on the saved latitude and longitude attributes.

    Then, to have Core Data automatically notify obervers of changes, you would implement the following method in your Location class:

    + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
        NSSet *result = [super keyPathsForValuesAffectingValueForKey:key];
    
        if ([key isEqualToString:@"degrees"] ||
            [key isEqualToString:@"minutes"] ||
            [key isEqualToString:@"seconds"]) {
    
            result = [result setByAddingObjectsFromSet:[NSSet setWithObjects:
                @"latitude", @"longitude", nil]];
        }
        return result;
    

    }

    This tells Core Data that the “transient” degrees, minutes and seconds are dependent on your latitude and longitude attributes. Assuming you’re using bindings, your user interface should update automatically. To prevent the user from editing the text fields, just set their behavior to “Selectable” or “None” in your XIB. (In XCode 3 I think you just uncheck the “Editable” box)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but

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.