I'm working with Core Data. Here is the class(generated by editor).
public class Tag: NSManagedObject {
}
And I defined an enum whose case has the same name as above.
enum NoteListType {
case Tag
case Album
}
When I tried to build it, I got this error message.
Use of undeclared type 'Tag'
When I CMD-click Tag to jump to its definition, it shows two options. Please help me. Many thanks in advance.
Update:
I tried to rename enum cases but still got undeclared type. Maybe it's caused by Xcode 8.2.1 and Core Data.
And I have published my project on Github. Here is the link.
I downloaded your git project and found out that this conflict is arising because of Target Membership of each file has both entity and Target so OS was unable to detect which class is referenced. I checked out the membership from Entity (kept only target) and the Tag ,Album were detected. Although I was unable to run the code as i got some compile team errors as you were trying to directly type cast NSManagedObject at some places . Please refer below screenshot .
I hope this helps you out.
Try this ..
enum NoteListType {
case tag
case album
}
Related
This question already has an answer here:
Added a custom framework, now Swift can't unarchive data
(1 answer)
Closed 2 years ago.
I have moved part of my code into a separate framework, and that framework contains a model used by the app to persist data to CoreData. Now when I try to launch the app, and it tries to restore state from CoreData, I get the following error.
2020-06-17 21:01:42.549851-0400 Project[17576:2986881] [error] fault: exception raised during multi-threaded fetch *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Project.Track) for key (NS.objects) because no class named "Project.Track" was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target). If the class was renamed, use setClassName:forClass: to add a class translation mapping to NSKeyedUnarchiver ({
"__NSCoderInternalErrorCode" = 4864;
})
It worked as expected before splitting the code off into a separate framework. I have tried to import the framework into each class that uses CD, and I have even tried to map it to the class' new namespace using Framework.Track, but I am still getting this error. Has anyone encountered this, and if so can you share some insight into resolving the error? I appreciate any help.
I found the answer, it was as specified by the exception. I just had to set the class name using the app's namespace to the new imported class, as so:
NSKeyedUnarchiver.setClass(Track.self, forClassName: "Project.Track")
Hope that helps someone.
I am getting this error on generating an NSManagedObject in Xcode 8.1 in Swift.
:0: error: filename "DemoOne+CoreDataClass.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataClass.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataClass.swift'
:0: note: filenames are used to distinguish private declarations with the same name
:0: error: filename "DemoOne+CoreDataProperties.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataProperties.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataProperties.swift'
:0: note: filenames are used to distinguish private declarations with the same name
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
I searched for this and got answers saying the file might be present twice in the project which is not my case. Another solution I came across was to remove the file from the build phase and add again. That too didn't work. Is it some build setting configuration mistake ? Or something else?
Here is the link with a demo project created with Xcode 8.1 and showing this problem:- https://www.dropbox.com/s/xwyzhshktb2hqe7/demo2.zip?dl=0
The issue is happening because of the Xcode automatic subclass generation feature.
According to What's New In Core Data
Xcode automatic subclass generation
Xcode now supports automatic generation of NSManagedObject subclasses
in the modeling tool. In the entity inspector:
Manual/None is the default, and previous behavior; in this case you
should implement your own subclass or use NSManagedObject.
Category/Extension generates a class extension in a file named like
ClassName+CoreDataGeneratedProperties. You need to declare/implement
the main class (if in Obj-C, via a header the extension can import
named ClassName.h).
Class Definition generates subclass files named
like ClassName+CoreDataClass as well as the files generated for
Category/Extension.
The generated files are placed in DerivedData and
rebuilt on the first build after the model is saved. They are also
indexed by Xcode, so command-clicking on references and fast-opening
by filename works.
So for fixing your issue, you need to set the Codegen field value to Manual/None as shown below:
This is what I did to fix this issue,
Select your entity in the data model
Set the Module to Current Product Module
Leave the Codegen to Class Definition though Manual/None also works
Select Editor > Create NSManagedObject Subclass
May help someone, Go to project compile source delete the extra reference if any.
Select code data model then select the Entity change the value of 'Codegen' to Manual/None.
It will work.
The issue was due a second file named:"Extensions.swift" in my project.
After deleting the duplicate "Extensions.swift" the error got resolved. Your error message might tell you which file is duplicated.
In my case Data Model (as example: MyCoreData.xcdatamodeld) was listed twice under Editor -> Create NSManagedObject Subclass... And here was reason why it was getting this type of error.
What I did:
I did delete MyCoreData.xcdatamodeld file.
Created another Data Model as example MyCD.xcdatamodeld.
Checked is here duplicated Data Models in here: Editor -> Create NSManagedObject Subclass...
Clean and later build for two times.
It happened to me when I copied and renamed entity. It failed to rename the class, so do it manually.
I just restart my Macbook and that clean my build folder. And it works like a charm!
I tried to include a class called 'name' and I got an error:
Swift Compiler Error: Use of unresolved identifier 'name'
The class exists and doesn't contain any compile errors.
There could be a few possible issues.
One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.
If it's Objective C class, check that the class is in ObjectiveC bridging header file.
If it's NSManagedObject subclass. Add #objc(className) before the class declaration.
If it's part of a different framework, make sure that the class or function is public
I had this one too. You will probably find that your first class is included in your testing module and that "name" isn't. Simply, if you include a class in testing, then every class that it references has to be in testing.
I had this problem too. I was trying to reference Class 1 within the code in Class 2. My problem was that Class 2 had target memberships in A and B, and Class 1 only had Target Memberships in Class A.
You can fix this by opening the Utilities Tab (farthest right button on the top bar of the Xcode window), and make sure that the same boxes are checked for both classes in the Target Membership subsection.
Got problem solved by
Target -> Build Phases -> Compile Sources -> Adding the class file
Add one more to the list.
If it is part of another framework, make certain that the "Build Active Architecture Only" settings are the same.
I'm currently trying to write a little iOS application in swift, where I have these Classes:
masterTableViewController addViewController and deleteViewController, each of them is connected to a, like the name already tells, viewController. The masterTableViewController should sent some data using the predefined function:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if(segue.identifier == "showDetails") {
var selectedIndexPath:NSIndexPath = self.tableView.indexPathForSelectedRow()!
var deleteViewController:deleteViewController = segue!.destinationViewController as deleteViewController
deleteViewController.todoData = todoItems.objectAtIndex(selectedIndexPath.row) as NSDictionary
}
I want to send the data of the current row to the next, by segue referenced controller.
This is where I get an error message stating that deleteViewController is not a type that can be assigned to a variable.
But I don't really understand what the problem s right now. Basically this should work because I just want to create a new object of the type my class is of and pass this one to my view controller.
In the reference I got this code from everything worked just fine.
You are mixing class names and instance variable names. Class names should be upper case: MasterTableViewController, AddViewController, DeleteViewController
At first, try to distinguish between the class name and the instance variable name by choosing a different name, i.e.:
var dvc:deleteViewController = segue!.destinationViewController as deleteViewController
dvc.todoData = ...
And see if it works
Another scenario where you might get mysterious 'use of undeclared type': the type (here DeleteViewController class) is defined in a file that you renamed by changing the 'Name' text box of the 'Utilities' pane. Then Xcode MIGHT not think the file is a member of the target, even though the checkboxes in the 'Target Membership' section of the 'Utilities' pane shows that the file IS a member of the project target. The workaround is to uncheck and recheck the checkbox that makes the file a member of the target. Xcode will reindex the project files and hopefully now consider the file a member of the target.
This can occur if the class you are compiling is included in a unit test module, but the class that is not defined is not.
You will find that the app compiles and runs, but compilation errors may be shown in the source.
Open the right bar and check the Target Membership settings. They should be consistent for both classes.
I realize you already have an accepted answer, but I've been chasing this error for too long and finally found the cause of my issue so maybe it'll help someone keep their sanity.
I encountered this issue when trying to integrate the Google admob sdk.
Here are the steps I took to debug:
Added 'import GoogleMobileAds' to the top of the view controller.
Added the frameworks using CocoaPods, tried again added it manually.
Checked the header search paths in Build Settings as well as the framework search paths. Verified that paths actually pointed to the frameworks I wanted to add.
Checked that the framework was included in the target I was trying to build.
Cleaned and tried to run, restarted and tried to run.
Revisited Build Settings, noticed framework search paths had a path with hyphens "-" (my_base_dir/my_project_dir/Pods/Google-Mobile-Ads-SDK/Frameworks). I've had issues with hyphens before so I changed the hyphens to underscores "_" and suddenly Xcode resolved the 'undeclared type' errors.
So apparently Xcode doesn't like hyphens in framework search paths.
I apologize for such a long message in advance, but I'm trying for detail here...
I'm working on using bTouch to create a compiled dll for referencing the ArcGIS iOS SDK.
When running bTouch using :
/Developer/MonoTouch/usr/bin/btouch libArcGIS.cs
it returns the following error
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(39,31):
error CS0102: The type `IncidentReportApp.AGSMutablePolygon'
already contains a definition for `selAddPointToRing'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolygon.g.cs(38,31):
(Location of the symbol related to previous error)
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(39,31): error CS0102:
The type `IncidentReportApp.AGSMutablePolyline'
already contains a definition for `selAddPointToPath'
/tmp/fp2ivuh8.3gj/IncidentReportApp/AGSMutablePolyline.g.cs(38,31):
(Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings
I checked my cs class and neither type is referenced\invoked. I'd like to understand why this message is occuring.
I have tried to use the instructions (and downloaded) code by Al Pascual at How to use the ArcGIS iPhone SDK with MonoTouch to call the Map View, but when attempting to launch the view with the code causes a crash. When I try to debug, it locks up when adding a mapping layer. I tested this with the MKMapView, but didn't experience the same behavior.
The error means that you defined more than one method mapping the same objective-C method.
Without the source, it is hard to diagnose.
I'm doing the same thing actually, I heavily modified the old "parser" library and am working on doing it now, hopefully dropping it in the public domain.
I'm seeing a similar (and probably related) problem in the ApiDefinition, there is a class AGSGPResultLayer that derives from AGSDynamicLayer. The AGSGPResultLayer overrides a property called Credential among other and since both are defining the same property.
How should over-riden properties be handled in bTouch? I'm guessing I'm missing something in the syntax.
Use the solution I provide with the correct bindings