Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add support for Creating/Deleting On Demand Resource Tags #298

Open
ignkarman opened this issue Jan 28, 2021 · 4 comments
Open

[FEAT] Add support for Creating/Deleting On Demand Resource Tags #298

ignkarman opened this issue Jan 28, 2021 · 4 comments

Comments

@ignkarman
Copy link

ignkarman commented Jan 28, 2021

Is your feature request related to a problem? Please describe.
On Demand Resource tags can only be manipulated through Xcode's project settings GUI. This is very annoying when you have processes that install new resources into your application, but then need to manually tag their resources

Describe the solution you'd like

  • Asset Tags are defined in the KnownAssetTags object in the 
 /* Begin PBXProject section */
    It seems it would be fairly easy to mutate this list.
  • Additionally, each file references it's created ODR tag at the end of it's resource declaration
    6A73EA5125C074F800669235 /* 265 in Resources */ = {isa = PBXBuildFile; fileRef = 6A73EA2725C074F000669235 /* 265 */; settings = {ASSET_TAGS = (265, ); }; };

Describe alternatives you've considered
Doesn't seem to be any support for this in the ecosystem, seems people are mutating their pbx files directly via shell scripts. Would be nice to add to this very nice library :)

@kronenthaler
Copy link
Owner

Thanks for reporting this. Although there is no direct API to do this operation in one go, all APIs to achieve it are available at the moment.

I haven't tried it myself, but something like this will get you going:

  • Retrieve the Project object:
project = XcodeProject.load(<path>)
project_object = project.get_object(project.rootObject)
  • Add the KnownAssetTags list to the attributes of the project
project_object.attributes['KnownAssetTags'] = ['tag1', 'tag2']
  • Locate all the resource's PBXBuildFile objects involved and add the ASSET_TAGS to the settings. This normally are returned when the resource is added using add_file
build_files = project.add_file('path-to-resource')
for build_file in build_files:
    build_file.settings = { "ASSET_TAGS" = [265] } # or whatever number needs to be there.
  • Save as usual.

I will keep the issue open, if this solution works it can be an starting point for the improvement.

@kronenthaler kronenthaler changed the title [Add support for Creating/Deleting On Demand Resource Tags] [FEAT] Add support for Creating/Deleting On Demand Resource Tags Jan 28, 2021
@ignkarman
Copy link
Author

@kronenthaler Thanks for the quick response! I will give this a go, and if all looks good, I may take a stab at contributing, and open a PR

@xiushaomin
Copy link

@ignkarman Did you finally solve this problem?

@mjordanBetBright
Copy link

mjordanBetBright commented Jan 22, 2024

I believe I got this to work using the below

    build_file.settings = PBXGenericObject(project).parse({
        'ASSET_TAGS': [tag, ]
    })

where 'tag' is the tag you want to use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants