Skip to content

Instantly share code, notes, and snippets.

@kanekoa
Created June 22, 2013 11:42
Show Gist options
  • Select an option

  • Save kanekoa/5840578 to your computer and use it in GitHub Desktop.

Select an option

Save kanekoa/5840578 to your computer and use it in GitHub Desktop.
Xcode Project Target Replicate
//
// main.m
// xptr
//
// Xcode Project Target Replicate
//
// Created by kanekoa on 2013/02/28.
// Copyright (c) 2013年 kanekoa All rights reserved.
//
#import <Foundation/Foundation.h>
#import "XcodeEditor.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSUserDefaults *arguments = [NSUserDefaults standardUserDefaults];
NSString *originTargetName = [arguments stringForKey:@"originTarget"];
NSString *destinationTargetName = [arguments stringForKey:@"destinationTarget"];
NSString *projectFilePath = [arguments stringForKey:@"projectFile"];
if (originTargetName == nil
|| destinationTargetName == nil
|| projectFilePath == nil) {
NSLog(@"Usage: xptr -originTarget <origintargetname> -destinationTarget <destinationtargetname> -projectFile <xcodeprojectfilepath>");
exit(1);
}
XCProject *project = [[[XCProject alloc] initWithFilePath:projectFilePath] autorelease];
XCTarget *destinationTarget = [project targetWithName:destinationTargetName];
if (destinationTarget == nil) {
NSLog(@"destination target is not found: %@", destinationTargetName);
exit(1);
}
XCTarget *originTarget = [project targetWithName:originTargetName];
if (originTarget == nil) {
NSLog(@"origin target is not found: %@", originTargetName);
exit(1);
}
NSLog(@"replicate target members to \"%@\" from \"%@\" in %@",
destinationTargetName,
originTargetName,
projectFilePath);
NSMutableArray *destinationTargetMemberPaths = [NSMutableArray array];
for (XCSourceFile *sourceFile in destinationTarget.members) {
[destinationTargetMemberPaths addObject:sourceFile.name];
}
for (XCSourceFile *sourceFile in originTarget.members) {
if (sourceFile.type != SourceCodeObjC
&& sourceFile.type != PropertyList
&& sourceFile.type != XibFile
&& sourceFile.type != ImageResourcePNG) continue;
if ([destinationTargetMemberPaths containsObject:sourceFile.name]) continue;
[destinationTarget addMember:sourceFile];
NSLog(@"Add %@", sourceFile);
}
[project save];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment