NSManagedObject subclasses duplicate declaration - swift

So, when my data model is ready, I tried to generate the subclasses when my data model file is open:
Editor -> Create NSManaged Object Subclasses
Okay, two files are generated, one is class declaration, the other is the property.
However, I was immediately prompted that I did a redeclaration of a class that already exists. This is where the original generated files are:
previously generated files
My question is obvious:
When were those two files generated?
What to do if I want those files in my project navigator, and, of course, the same folder as my ViewController?

It is common to make changes to an existing entity on the core data model.
Assume you add a field to an existing entity in the core data model, you would have to regenerate the class for that entity to include that field.
When regenerating that class there would be a an option to overwrite the existing files.
To answer your questions:
It was probably created when the previous entity change was made.
Move the previously generate files to the desktop. Then generate new files. See what the difference between the 2 sets of files are and take appropriate action. If I am not wrong, one file would be an extension and one is a class file.

You are generating files which have already been generated for you by Xcode and thus get duplicate declarations.
Find detailes in this answer.

So, the correct answer seems like the one who commented on my question. Original post is here: https://stackoverflow.com/a/39933534/5642467.
Delete all generated NSManagedObject subclasses from your project, if exists.
Set Codegento Manual/None in your .xcdatamodel for all entities
Clean project.---This is the key step, which is by default set to automatic by Xcode8.
Clean DerivedData folder
Restart Xcode
Manually generate NSManagedObject subclasses (in "Editor" menu)
Make sure those files are added to your project
build
If your problem persists, repeat:
Clean project
Clean DerivedData folder
Restart Xcode

In your xcdatamodeld you have to modify the Entity Class Codegen to Manual/None in the Utilities Panel before compile

Related

How to retrieve properties in "Entity+CoreDataClass" from "Entity+CoreDataProperties" when using CoreData?

I used CoreData recently, trying to implement it into an existing project. To extend existing functions in my old class into CoreData, I changed Codegen to Category/Extension. After Editor > Create NSManagedObject Subclass..., I got two files, namely Entity+CoreDataClass and Entity+CoreDataProperties.
However, when I copy my old methods into Entity+CoreDataClass, it report errors "Ambiguous use of 'xxx'". Also, there are some "Invalid redeclaration of 'xxx' errors in Song+CoreDataProperties". Why it comes and how can I solve it?

How can I include a mxj Java jar/class folder in a freezed m4l-Device?

I have a maxforlive device using java/mxj.
I used all of these options to include my java files during development:
Including my (maven) target/classes directory through max.java.config.txt.
Adding a directory through Options > File Preferences
Adding a jar to the automatically generated (OSX) ~/Documents/Max 7/Max for Live Devices/MyProject Project/ directory
All of these paths work fine i.e. the files are picked up and my mxj object works.
However, when i freeze the device for publication, java files are not included from any of those paths.
I tried to make sense of
https://docs.cycling74.com/max7/tutorials/jitterchapter99_appendixd although I'm not building a standalone, but a freezed maxforlive device, so I included max.jar and mxj.mxo in the Project folder which did not work either.
When I copy my target/classes or target/classes/myproject folder into the generated Project folder (/code, /code/classes, /classes), max moves all the class files out into /code, creating a lot of work for me while not even picking the classes up for dev.
I saw devices on maxforlive.com with properly included java files, so I know it can be done. How can I achieve this?
Unfortunately this is a long standing bug in MFL.
Here is a movie from 2012 where I reproduce this, it has not been fixed since. http://arttech.nl/projectjavaissue.mov
This means that the only way to distribute MFL devices with java class files is to include them separately.
Ok, so here it is: Including just a single class with no other class dependencies except MaxObject works fine. There's also no need to add .java files like I said in my previous comment.
All you need to do is:
have the working mxj object in your patcher (doesn't matter where you saved it)
click the button on the bottom that says "Show containing project" on hover
add your classfile
freeze
When you have more classes, it gets complicated.
1) If you have your typical java hierarchy with folders and subfolders, that won't work. As you have to add each file separately, the hierarchy will be destroyed. Use a jar and add it to the containing project.
2) Here it comes, believe it or not: All the classes you are going to use will have to be loaded on first instantiation. I call it static class allocation ;)
A way to achieve that:
create a new instance of every class in the constructor of the class that extends MaxObject or any other constructors it calls. That includes classes with only static methods.
if you happen to use interfaces and create implementations of those dynamically (new Runnable() {...}), don't. Dynamic implementations are new classes.
Fun fact: you can override methods of classes, too. So go
class Runner {
public void run() { throw new Exception("not implemented"); }
}
then you can dynamically create a
new Runner() {
public void run() {
MaxObject.post("Even Mr. Gosling says interfaces were a mistake!");
}
}
Don't believe it? I don't blame ya. Look at
https://github.com/mihop/mxj-wsserver
and
http://www.maxforlive.com/library/device/3809
to be converted.

FileA.Swift <--> FileB.Swift Scope: Accessing public entities

Is there a way to access typealias, functions, classes and structs defined in one .swift file from another .swift file?
I attempted to access a public func() and public class() defined in one .swift file from a different .swift file but failed:
Environment.swift:
MainViewController.swift:
Apparently my Xcode project got corrupt.
I created a new project and repeated the pattern.
...occasionally, I find that a Xcode/Swift project appear to work like a 'loose light bulb' that needs to be tweaked/cleansed... or replaced to have a working solution.
This time it works.

Entity Framework 5 model first - Where is IDisposable gone?

In Entity Framework 5 model first, there seem to be some breaking changes due to the way the class files are generated (No more code generation, but T4 templates)
2 examples:
The generated context file doesn't implement IDisposable anymore
There isn't a constructor which takes a connectionstring anymore
Are there more breaking changes? And what is the solution to them?
The default code generated from a model in Entity Framework 5 now inherits DbContext instead of ObjectContext.
This still implements IDisposable, but if you're getting an error from a line of code similar to this:
using (var mymodel = new MyModelContext()) { ... }
...complaining about not implementing IDisposable, then your problem is most likely that your model is defined in a separate assembly that references EF5 and you have not added an EF5 reference to your project.
As Ladislav Mrnka has already mentioned in his answer, if you want to pass a connection string to the constructor you have to create your own constructor manually to do this.
If you want to switch Entity Framework back to the older style of generated code, which will automatically generate the constructor you're looking for, then follow these steps:
Click on the designer surface of your EDMX file, and look at the properties window. Find a property called "Code Generation Strategy" and set this to "Default" instead of "None". This will tell Visual Studio to start creating the code for your object model in MyModel.Designer.cs in one big file, this time using ObjectContext instead of DbContext.
Delete the following sub files from below your EDMX file: MyModel.Context.tt, MyModel.tt. These are the auto generated files that you don't want anymore. If you don't delete them you'll get class naming conflicts because your objects will be created twice.
The generated context file doesn't implement IDisposable anymore
IDisposable is still implemented by the parent context type. The generated type is still disposable.
There isn't a constructor which takes a connectionstring anymore
It now uses convention to get connection string but you can add your own constructor either to template or to your partial class part of the context.
Are there more breaking changes? And what is the solution to them?
It is whole breaking change because it uses different API - DbContext API instead of ObjectContext API which means different types, different methods, POCO entities etc. If you want to get back to original code generation you have to delete those T4 templates and enable code generation as described in .Designer.cs file but the current recommended way is to use POCOs and DbContext API.
I was having the same issue with the using statement needing a type that extended IDisposable... Turns out that I forgot to reference System.Data.Entity in my project... Added the reference and it fixed the problem.
Just clean and build the project, don't forget to add the reference to your entity.

how to create new class files based on existing ones - in Xcode

Is there a way to create a new class based on another which already exists in the project?
Ideally one could just make a copy of a group (which may inlude .h, .m -xib) and change whatever code on this copy to create a new class.
Currently I create a new group, create the new class with it's new name and then copy the code for these files - immediately renaming the old class name into the new class name
The alternative would be to do "Show in Finder" and create duplicates for the files, drag them back into xCode, create a new group and drag them there...
Is there some better way to do this?
ps in Eclipse there is even an explicit option in the menu for this purpose
Many thanks
I think you should use a subclass for that. Create a new Objective-C class, and choose your old class as the parent class.
Have a look a this, it may help you understand this principle if you're not familiar with it : http://www.techotopia.com/index.php/Objective-C_Inheritance
The concept of inheritance brings something of a real-world view to programming. It allows a class to be defined that has a certain set of characteristics (such as methods and instance variables) and then other classes to be created which are derived from that class. The derived class inherits all of the features of the parent class and typically then adds some features of its own.
I don't know what will happen to the xib file, but at least you can re-use your classes as much as you want !