ioscore-dataxcdatamodel

Define Entity's Attribute's Value


I am trying to edit rawURL so that it looks in the correct folder within my application bundle. I looked at Apple's documentation, but when I opened up my application's .xcdatamodeld, the attribute whose String value I'm looking to edit, didn't appear to be set to anything:

enter image description here

I looked in the entire code base, and I couldn't find it set anywhere programatically. However, I put a print statement in the code I'm looking to change, and it does in fact print a string. I want to change the value of this string so that it looks in FindSpecies/[species name]/[img file] not FindSpecies/species/[species name]/images/[img file].

NSArray*    paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
        NSString*   cachePath = [paths objectAtIndex:0];
        NSString*   resourcePath = [[NSBundle mainBundle] resourcePath];
        NSLog(@"self.rawurl: %@", self.rawURL);
        NSString* stringURL = [self.rawURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
        NSLog(@"stringURL: %@", stringURL);
        NSURL* url = [NSURL URLWithString:stringURL];
        NSString* path = [url path];
        NSString* query = [url query];
    //...
        returnString = [NSString stringWithFormat:@"%@/%@%@", resourcePath, kThumbnailDirectoryName, path]; 

Can I edit rawURL if I don't even know where/how its set in the first place?

EDIT: This app was built in 2011 by my professor's former grad students. I am in the process of modernizing it.


Solution

  • There's no reason to expect rawURL to have a value in the model editor you show in your screenshot. That defines the schema for the Core Data persistent store, not the data. It might have default values but those aren't required.

    If rawURL has a value then it's being set somewhere. You have the source code, so you should be able to find it. If you can't, look again, because you can see it's happening somewhere. If your entity has a subclass of NSManagedObject, it might help to put a breakpoint at the rawURL property declaration in that class. The breakpoint should trigger any time the value changes.

    You can of course also change it any time you want on any object instance that has the property. Just assign a value, like any other string property.