[FEAT] Add support for Creating/Deleting On Demand Resource Tags
ignkarman opened this issue · 4 comments
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 :)
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 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
@ignkarman Did you finally solve this problem?
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