Error redeclaration of

I just finished roasting some coffee from Peru. I’ve never had it before, but it got me thinking about my Roaster On the Go “app” as I thought about the context that I could use to show you the solution to the compiler error described in the title. I used this to demonstrate Working with Unwind Segues Programmatically in Swift, but now I’m going to use it to show you how to resolve these errors that can crop up when you’re implementing NSManagedObject subclasses for your Core Data Entities.

I just finished roasting some coffee from Peru. I’ve never had it before, but it got me thinking about my Roaster On the Go “app” as I thought about the context that I could use to show you the solution to the compiler error described in the title. I used this to demonstrate Working with Unwind Segues Programmatically in Swift, but now I’m going to use it to show you how to resolve these errors that can crop up when you’re implementing NSManagedObject subclasses for your Core Data Entities.

Scenario – Adding a data model

The “app” doesn’t currently use Core Data, but for this article, I’ve created a rudimentary data model that includes a single Entity called Product:
RoasterOnTheGo_xcdatamodel

Now suppose that I’m ready to implement a subclass of NSManagedObject for the Product Entity.

Doing so right now using Xcode 8’s default settings is going to give me all kinds of issues.

To be clear, I’m using Xcode 8.2 for this scenario.

The error that I’m getting when I attempt to build after creating a subclass of NSManagedObject for the Product Entity is one of the following (depending on how you choose to create the NSManagedObject subclass):

Invalid redeclaration of ‘Product’

or

‘Product’ is ambiguous for type lookup in this context

or in the compiler output

filename “Product+CoreDataClass.swift” used twice

What’s happening??

This is a conflict with Xcode 8’s auto codegen for NSManagedObject subclasses. In some versions of Xcode 8 (version 8.2, for example), this auto codegen is turned on by default. This can present a problem if you intend to manually create NSManagedObjectSubclasses for your Entities.

Solution

To solve this problem, or to avoid it before it occurs, you essentially need to turn off Xcode 8’s auto code generation feature for NSManagedObject subclasses if you intend to implement your NSManagedObject subclasses manually (my personal preference).

Take a look at the steps below to get your project building again:

1 – Turn off automatic code generation for NSManagedObject subclasses

Open your data model (the .xcdatamodeld file in your project).

Click on each Entity in your data model and in the Data Model Inspector of the Utilities Pane, change the Codegen property from “Class Definition” or “Category/Extension” to “Manual/None”:

Turn code generation off

2 – Choose module

You also need to tell Xcode where it can look to find a definition for the NSManagedObject subclass that you will implement for this Entity by choosing “Current Product Module” for the Module value:
Choose "Current Product Module" as module value

Save your .xcdatamodeld file.

3 – Clear derived data

Behind the scenes, Xcode creates files and implements Types for the Entities in your data model. It puts them in your derived data folder and automatically traverses this folder to look for Type definitions for Core Data Entities. So in order to get your project building again, you need to get rid of those files that Xcode created automatically.

The “big hammer” for this is to simply clear all of your project’s derived data. To do this, click on the Products menu, hold down the Option key, and click “Clean build folder…”:

Product -> Press Option Key -> Clean Build Folder...

Alternatively, you could opt to go in and delete the only auto-generated Swift files, but you’ve got to do some digging.

Click on File -> Project Settings:
File -> Project Settings

Next, click on the arrow next to the path leading to your default derived data folder:
Click derived data folder arrow

Next, find the folder for your project at the root of your default derived data directory (where you were taken in Finder when you clicked the arrow in Project Settings). Then get ready to dig…

Click Build -> Intermediates -> ProjectName.build -> Debug-iphonesimulator -> ProjectName.build -> DerivedSources -> CoreDataGenerated -> ProjectName

Delete the .swift files in this folder.
Path to auto-generated Entities

4 – Rebuild

After you rebuild, any compiler errors you previously had, related to “ambiguous Type” or “redeclaration of Type” should be resolved!

comments powered by

Перезапись массива

  • Войдите на сайт для отправки комментариев

titanbox

Offline

Зарегистрирован: 28.05.2014

Добрый день!

Пытаюсь перезаписать данные в массив, но возникает ошибка:

Blink.ino: In function ‘void loop()’:

Blink:7: error: redeclaration of ‘int ara [5]’

Blink:5: error: ‘int ara [5]’ previously declared here

Как быть?

void setup() {                
}

void loop() {
  int ara[5] ={1,2,3,4,5}; 
  //.........
  int ara[5] ={3,8,1,2,9}; 
}

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 12:50

#1

Geronimo

Offline

Зарегистрирован: 06.05.2013

Не объявлять массив дважды

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 12:54

#2

titanbox

Offline

Зарегистрирован: 28.05.2014

Тогда следующий вопрос: как перезаписать данные в массиве?

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 12:54

#3

Geronimo

Offline

Зарегистрирован: 06.05.2013

Если убрать инт у второй строчки работает?

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 12:56

#4

titanbox

Offline

Зарегистрирован: 28.05.2014

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 13:25

#5

__Alexander

Offline

Зарегистрирован: 24.10.2012

обращайтесь к каждому элементу отдельно.

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 13:38

#6

titanbox

Offline

Зарегистрирован: 28.05.2014

__Alexander пишет:

обращайтесь к каждому элементу отдельно.

В этом и проблема.

Суть в следующем:

В программе есть несколько блоков (массивов) данных:

010102030020303020003…

012930201210210201201.. и т.д.

Как их хранить? В разных массивах?

Я хотел использовать 1 массив и перезаписывать его по мере надобности.

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 13:54

#7

__Alexander

Offline

Зарегистрирован: 24.10.2012

типа один в озу, а остальные во флеш?

ну так перезаписывайте поэлементно.

for(char count = 0; count < 10; count++)

massRAM[count] = massFlash[count];

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 13:57

#8

titanbox

Offline

Зарегистрирован: 28.05.2014

Все становится сложнее..

А как запихать статические данные во flash?

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 14:02

#9

__Alexander

Offline

Зарегистрирован: 24.10.2012

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 14:08

#10

titanbox

Offline

Зарегистрирован: 28.05.2014

Я имел в виду не програмно а ручками.

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 14:17

#11

__Alexander

Offline

Зарегистрирован: 24.10.2012

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 14:19

#12

titanbox

Offline

Зарегистрирован: 28.05.2014

Понятно(

Буду копать в другую сторону.

Большое спасибо Alexander.

  • Войдите на сайт для отправки комментариев

Ср, 28/05/2014 — 23:24

#13

kisoft

kisoft аватар

Offline

Зарегистрирован: 13.11.2012

Во флеш можно записывать, но в Вашей задаче это не нужно. Не парьте мозги. Лучше задачу сформулируйте подробней.

  • Войдите на сайт для отправки комментариев

Hello all, I have a strange error that I can’t figure out. I believe the source of the error is simple, but I can’t see it. Here’s what I’m doing:

I’m building a Dll using VC++ 2008. Call it «MyDll». Within this Dll I am defining objects to use «inside» of it i.e. these objects are not exposed to anyone using the Dll. Let’s say I have defined a class called «CMyFirstClass» and specified in files «MyFirstClass.cpp/.h».

MyFirstClass.h:

class CMyFirstClass
{
     public:
         — some vars here — 
         — some funcs here —

     private:
        — some vars here —
        — some funcs here —
}

MyFirstClass.cpp:

#include «MyFirstClass.h»

CMyFirstClass::CMyFirstClass()
{
.
.
.
}

etc..

In «MyDll.cpp» I’d like to instantiate an object of type «CMyFirstClass» and therefore I have added:

#include «MyFirstClass.h»

at the top of «MyDll.cpp» along with the other includes and within the code body I instantiate a «CMyFirstClass» object and use it. The project compiles and executes properly.  Now…I add a second class called «CMySecondClass» to the dll project. In this class I’d like to make use of some utility contained in «MyFirstClass». To do so I’d like to instantiate an object of type «MyFirstClass». Therefore I have the following header file for «MySecondClass»:

MySecondClass.h:

#include «MyFirstClass.h»

class CMySecondClass
{

     public:
      — some vars here —
      — some funcs here —

     private:
        CMyFirstClass object1;
       — some funcs here —

}

I won’t bother to show the cpp file for the second class as I don’t think the problem resides there. Since I want to instantiate objects of type «CMySecondClass» in my dll.cpp code, I now have the following in the include section at the top of «MyDll.cpp»:

#include «MyFirstClass.h»
#include «MySecondClass.h»

Now when I compile this project I get the following compiler error:

«error: invalid redeclaration of typename «CMyFirstClass» declared at line 4 of «C:…MyFirstClass.h».  

Line 4 is the «class CMyFirstClass» line in the «MyFirstClass.h» header file as shown above. If I comment out the «#include «MyFirstClass.h» line in MySecondClass.h file as well as the object declaration in the private section of this class, the project compiles. Of course, I can no longer get any utility from «CMyFirstClass» in «CMySecondClass» objects. Does anyone know what is going on here? I sure hope so. Thanks in advance!

-L

Понравилась статья? Поделить с друзьями:
  • Error remaining connection slots are reserved for non replication superuser connections
  • Error relocation symbol not found
  • Error reload the page bitrix captcha
  • Error reliable snapshot overflow
  • Error relative branch out of reach