I have searched a bit but I cannot find an easy way to tell xcode to regenerate all the NSManagedObject subclasses on build. I would do this to be able to take all those classes off our git repository and only committing the model, and at the same time be sure that no one runs into problems because the classes are not in sync with the model
If you use something like mogenerator (http://rentzsch.github.com/mogenerator) to generate your model classes, you can get it to run as a script as per above suggestion.
This way, every time you trigger a build, the mogenerator script will run first making sure your classes have been updated according to the object model file.
Here's a good article to guide you through it http://www.esenciadev.com/2011/05/mogen-and-xcode4-integration/
You could add a run script.
Select your target and then select "Build Phases". From the "Add Build Phase" button in he lower right choose "Add Run Script".
No write a shell script, perhaps invoking an AppleScript or Automator script that instructs Xcode to generate the files. I have looked at the Dictionary of Xcode (Choose Xcode with "Open Dictionary" from the AppleScript Editor), and there are hooks select the entities in your data model. I did not see a way via AppleScript to generate the files, but you could have it choose the corresponding menu item.
This is quite a little project. Please share your code once you got it to work.
I wrote a script that generates NSManagedObject subclasses like Xcode does (classes and categories).
cdgenerator
It is very easy to use.
Related
I am building a project on Github written in Objective-C. It resolves MAC addresses down to manufacturer details. The lookup table is currently stored as text file manuf.txt (from the Wireshark project), which is parsed at run-time, which is costly. I would prefer to compile this down to archived objects at build-time, and load that instead.
I would like to amend the build phases such that I:
Build a simple compiler
Run the compiler, parsing manuf.txt and outputting archived objects
Build the framework
Copy the archived objects into the framwork
I am looking for wisdom on how to achieve steps 1 and 2 using Xcode v7.3 as Xcode provides only a Copy Files phase or a Run Script phase. An example of other projects achieving similar goals would be inspiring.
I suspect that what you are asking is possible, but tricky. The reason is that you will need to write a bunch of class files and then dynamically add them to the project.
Firstly you will need to employ a run script phase to run various tools from the command line to parse your file and generate a number of class files from it. I would suggest looking into various templating engines. For example appledoc uses moustache templates to generate API documentation files. You could use the same technique to generate header and implementation files.
Next, rather than generating archived objects an trying to import into a framework. I think you may be better off generating raw source code, adding it to a project and compiling into a framework. Probably simpler in the long run.
To automatically include the generated code I would look into (which means I haven't actually tried this :-) adding a folder reference to the project rather than an Xcode group. Folder references are an option in the 'Add files to ...' dialog.
Folder references refer to a directory and automatically add the entire contents of that directory to a project. So you can use one to point to the directory where you have generated the source code. This is a much better option than trying to manipulate the project or injecting things into an established framework.
I would prefer to parse the file at runtime. After launch you can look for an already existing output, otherwise parse it one time.
However, I have to do something similar at Objective-Cloud. I simply added a run script build phase and put the compiler call into it.
I am working on a project and I have a plan to separate certain sections out into separate dlls/ndlls in the final program. The main reason I want to do this is to support plugins and add ons, so more functionality can be added if needed, but the core app can still be used if that's the only requirement.
I have done something similar in C# (abet through an IDE so I never had to write any linker/compiling commands) so I know the general process but I can't seem to find a way to write HX code and then have it compile into a ndll.
I found this http://old.haxe.org/doc/cpp/ffi?lang=en which shows how to compile cpp code into a ndll using hxcpp and g++. I would think there should be a way I can use LIME or HXCPP to create a build file that will allow me to do it in one step instead of having to make a "fake" main function to compile the HX to CPP or CS.
If anyone knows of a project that does this and has a build.hxml or build.xml file that describes this or a tutorial or guide that takes about this, I would love it see it.
Try this:
lime create extension TestExt
lime rebuild TestExt windows
Replace "windows" with "mac" or "linux" as appropriate. Assuming it works, the ndll will show up in a subfolder of TestExt/ndll/.
As for tutorials, I wrote this one. It's targeted at OpenFL programmers, but the "Writing code for iOS" section covers what you'll need to know. (You can also just model your code on the template.)
In case it helps, I've made a tool to generate some of the boilerplate code that Lime requires.
Some colleagues, now departed, had the habit of adding new classes within a related class file.
This makes refactoring painful.
Is there a tool, perhaps within XCode or AppCode or just a simple script, that will split up these monster files?
It appears there is a tool to help with this in AppCode, but it only semi-automates the process.
I'm using AppCode 2.0, I don't know if the same tool is available in AppCode 1.x.
To extract one class from a file to a new file, right-click the#interface or #implementation line and select Refactor > Move. Alternatively press F6 on that line. You can now enter a new file name, though you probably want to copy+paste the class name in here. At this point you can also select any defines you want to move.
I have done some work on a script to extract all classes in a file. I'd love to share this one day, when I get the chance to remove our clients code from the unit tests!
I don't think so there is any tool for this. However you can write your own osx application for doing the same.
The application will ask to browse the file, and it will search for #interface....#endand#implementation....~#end` and will create a file from this. If a single file contains two classes then it will result in for files (two headers and two implementation). Then the original file can be deleted manually or automatically.
I think this above task can be completed in few hours.
Here you can go for save the original file in a folder, just in case you want to rollback.
I'm currently working an Eclipse plug-in to provide iPOJO manipulation support.
The principle of iPOJO is to modify the .class files generated by the Java compiler to inject some methods and to add/update an entry to the Manifest.mf file.
Currently, my plug-in provides a project Nature and adds a Builder, added at the end of a project builder list, that calls the iPOJO Manipulator.
I use it on PDE projects.
The complete process works but I have a problem :
When my builder has finished its job (and the building process), the whole building process restarts, erasing the output folder and calling my builder again.
If I don't add a safety trick, it makes the building process loop over and over.
As I work on IResource, an IResourceDeltaEvent must be sent at the end of the building process, so I think the best way to avoid that kind of problem is to hide the fact that the resource has changed.
To be clear, I'm looking for a way to modify the class files after a PDE build, without inducing a new build, and without disabling the workspace auto-build property.
Thanks for answers.
I am a little unclear as to what you are describing.
You mention that you want this to work for PDE builds, but PDE builds happen largely outside of the workspace using ant scripts. They do not use IResource, Builder, or IResourceDeltaEvent.
I am guessing that you don't really mean PDE builds, but rather the building of plugin projects inside of the workspace.
In general, Eclipse (JDT in particular) expects that it has complete control over the output folders. However, there is an option in Preferences -> Java -> Building -> Output Folder called "Rebuild class files generated by others". Ensure that this is disabled. Eclipse should not try to rebuild class files that you touch. If your builder only touches class files then it will not trigger other builds after it changes the class files. The only thing is that you need to be careful not to compile things twice (and I think this is the problem that you are describing).
Alternatively, it may be easier for you to implement a CompilationParticipant (and the org.eclipse.jdt.core.compilationParticipant extension point). This will allow you to know exactly when JDT calls a compilation and exactly what it compiles.
Additionally, you will be notified of reconcile operations (ie- changes in working copies that have not been saved). This may be useful for you if you wanted to manipulate files as-you-type.
I am currently learning Objective C programming using Xcode. I am wondering how to have multiple main programs, i.e. source members with main method in it, in a single project? It is a bit inconvienient to put just one in each project, as I would have to create tons of them through my learning process. Or is there any better way to do it? All I want is to place multiple independent executable programs in a single project, though I only need to run on each time. Thanks a lot.
This is much more trouble than it's worth. Just create tiny test projects. I've got a huge directory of them that I throw away from time to time. I also constantly re-create a project called "Test" for building little projects.
For really, really tiny things, I do sometimes create a simple test.m file that has its own main and compile it by hand:
gcc -framework Foundation -o test test.m
But in that case I don't bother with Xcode.
EDIT You of course could replace gcc above with clang. For projects so small that I'm doing this, it hasn't been worth changing my muscle memory....
Each target can have a maximum of one main() method. So you need to create a different target for each program and put each main() into a different source file. Each source file with a main() in it can be comiled into only one target.
If your mini-projects are simple enough you could also put it all in one project, creating classes/methods for each subject that you would otherwise have created a new project for.
It could be a class "Experiments" or "Learning" with methods like "experimentWithSomeStuff" or "testSomething". You could instantiate this class in main and call just the method you are working on at the moment.
I did this when I learned ObjC-Basics and it worked fine for me.
This way you can quickly check your "older" experiments to refresh how something works.
I found out that you can make many applications, lets called them that, in the same Xcode project by creating new targets, and to test them individually, you just need to go to Product-> Manage schemes and choose the target you want to build and run.
I guess then Xcode runs the main associated to that target.