') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - superboonie/XcodeEditor: An API for manipulating Xcode project files. · GitHub
Skip to content

Repository files navigation

Description

An API for manipulating Xcode project files.

Usage

Adding Source Files to a Project

XCProject* project = [[XCProject alloc] initWithFilePath:@"MyProject.xcodeproj"];
XCGroup* group = [project groupWithPathFromRoot:@"Main"];
XCClassDefinition* classDefinition = [[XCClassDefinition alloc] initWithName:@"MyNewClass"];
[classDefinition setHeader:@"<some-header-text>"];
[classDefinition setSource:@"<some-impl-text>"];
[group addClass:classDefinition];
[project save];

Duplicating Targets

It will be added to project as well.

XCTarget* target = [project targetWithName:@"SomeTarget"];
XCTarget* duplicated = [target duplicateWithTargetName:@"DuplicatedTarget"productName:@"NewProduct"];

Specifying Source File Belongs to Target

XCSourceFile* sourceFile = [project fileWithName:@"MyNewClass.m"];
XCTarget* examples = [project targetWithName:@"Examples"];
[examples addMember:sourceFile];
[project save];

Adding a Xib File

This time, we'll use a convenience method on XCGroup to specify the targets at the same time:

XCXibDefinition* xibDefinition = [[XCXibDefinition alloc] initWithName:@"MyXibFile"content:@"<xibXml>"];
[group addXib:xibDefinition toTargets:[project targets]];
[project save];

Adding a Framework

XCFrameworkDefinition* frameworkDefinition =
[[XCFrameworkDefinition alloc] initWithFilePath:@"<framework path>"copyToDestination:NO];
[group addFramework:frameworkDefinition toTargets:[project targets]];
[project save];

Setting copyToDestination to YES, will cause the framework to be first copied to the group's directory within the project, and subsequently linked from there.

Adding an Image Resource

XCSourceFileDefinition* sourceFileDefinition = [[XCSourceFileDefinition alloc]
initWithName:@"MyImageFile.png"data:[NSDatadataWithContentsOfFile:<your image file name>]
type:ImageResourcePNG];
[group addSourceFile:sourceFileDefinition];
[project save];

Adding a Header

XCSourceFileDefinition* header = [[XCSourceFileDefinition alloc]
initWithName:@"SomeHeader.h"text:<your header text> type:SourceCodeHeader];
[group addSourceFile:header];
[project save];

Adding a sub-project

subProjectDefinition = [XCSubProjectDefinition withName:@"mySubproject" projPath=@"/Path/To/Subproject"type:XcodeProject];
[group addSubProject:subProjectDefinition toTargets:[project targets]];

Removing a sub-project

[group removeSubProject:subProjectDefinition]; //TODO: project should be able to remove itself from parent.

Configuring targets

We can add/update linker flags, header search paths, C-flags, etc to a target. Here we'll add header search paths:

XCTarget* target = [_project targetWithName:_projectName];
for (NSString* configName in [target configurations])
{
XCBuildConfiguration* configuration = [target configurationWithName:configName];
NSMutableArray* headerPaths = [[NSMutableArrayalloc] init];
[headerPaths addObject:@"$(inherited)"];
[headerPaths addObject:@"$(SRCROOT)/include"]; [configuration addOrReplaceSetting:headerPaths forKey:@"HEADER_SEARCH_PATHS"];
}

. . . these settings are added by key, as they would appear in a make file. (Xcode provides more human friendly descriptions). To find the key for a given build setting, consult the compiler docs. Common settings are:

  • HEADER_SEARCH_PATHS
  • OTHER_LD_FLAGS
  • CLANG_CXX_LANGUAGE_STANDARD
  • CODE_SIGN_IDENTITY
  • GCC_C_LANGUAGE_STANDARD
  • INFOPLIST_FILE
  • LIBRARY_SEARCH_PATHS
  • PRODUCT_NAME
  • PROVISIONING_PROFILE

File write behavior

//Creates the reference in the project and writes the contents to disk. If a file already exists at the //specified location, its contents will be updated.
[definition setFileOperationStyle:FileOperationStyleOverwrite]; 
//Creates the reference in the project. If a file already exists at the specified location, the contents will //not be updated.
[definition setFileOperationStyle:FileOperationStyleAcceptExisting]; 
//Creates the reference in the project, but does not write to disk. The filesystem is expected to be updated //through some other means.
[definition setFileOperationStyle:FileOperationStyleReferenceOnly]; 

Reports

You've just read them! The Source/Tests folder contains further usasge examples. A good starting point is to run the test target in Xcode. This will extract a test project to the /tmp directory, where you'll be able to see the outcome for yourself.

Build Status

Building

Just the Framework

Open the project in XCode and choose Product/Build.

Command-line Build

Includes Unit Tests, Integration Tests, Code Coverge and API reports installed to Xcode.

Requirements (one time only)

In addition to Xcode, requires the Appledoc and lcov packages. A nice way to install these is with MacPorts.

git clone https://github.com/tomaz/appledoc.git
sudo install-appledoc.sh
sudo port install lcov

NB: Xcode 4.3+ requires command-line tools to be installed separately.

Running the build (every other time)

ant 

Feature Requests and Contributions

. . . are very welcome.

If you're using the API shoot me an email and tell me what you're doing with it.

Compatibility

  • Xcode-editor has been tested on Xcode 4+. It should also work on earlier versions of Xcode.
  • The AppCode IDE from JetBrains is now supported too!
  • Supports both ARC and MRR modes of memory management.

Who's using it?

  • Apportable : Develop Android applications using Xcode, Objective-C and Cocoa APIs
  • expanz: A RAD framework that enables .NET developers in producing cross-platform and cloud apps.
  • Xamarin: The Calabash automated functional testing for mobile applications.
  • Level Helper: A RAD framework for developing 2D games on iOS & Android.
  • Text Mate: The missing Text Editor for OSX.

Authors

With contributions from:

  • Connor Duggan - lots of bug fixes, maintenance and enhancements.
  • Alexander Smirnov - Cleaned up, generalized and contributed back the changes from the Calabash fork.
  • Zach Drayer - lots of fixes and features to support TextMate.
  • Janine Ohmer - support adding and removing sub-projects (http://www.synapticats.com).
  • Bogdan Vladu - support adding and removing groups (www.levelhelper.org).
  • Chris Ross of Hidden Memory (http://www.hiddenmemory.co.uk/)
  • Paul Taykalo
  • Vladislav Alekseev
  • Felix Schneider - bug fixes.
  • Isak Sky - mutable XCSourceFiles.

Thanks!

LICENSE

Apache License, Version 2.0, January 2004, http://www.apache.org/licenses/

  • © 2011 - 2012 Jasper Blues and contributors.

About

An API for manipulating Xcode project files.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors