Value of type 'Category' (aka 'OpaquePointer') has no member 'name'

3.8k Views Asked by At

I'm working with Swift in Xcode and I receive the following error:

Value of type 'Category' (aka 'OpaquePointer') has no member 'name' 

And I've looked everywhere but I can't find a solution. Does someone know what to do?

Here is a screenshot: enter image description here

13

There are 13 best solutions below

0
Govind Ravaliya On BEST ANSWER

Category did not provide name property

enter image description here

0
Andrei Erdoss On

If you are following Angela Yu's course, I found that by selecting Manual/None and then Class Definition for the Category Entity under Codegen, the classes are auto-generated.

Also run cmd + b afterwards.

enter image description here

3
William Colbert On

I also had this occur when attempting the exercise in the Angela Yu course where Category is a core data entity. I was using Xcode 11.3.1. After several attempts of setting the Module to Current Product Module and Codegen to Class Definition followed by Ctrl-B's to rebuild, I still received the error. However, restarting Xcode solved the problem and code completion was then able to suggest the name attribute/property.

0
Azure On

Also in Angela's class. I found that by removing the core data models and reinitiating them as independent entities with no relationship, setting up the save and load functions, running the app, and then going back to link the relationship solved the issue. I think it has to do with saving the entities as NSManagedObject before being able to reference the attributes. I am guessing that without initiating them as an NSManagedObject the default type is Opaque Pointer. Best of luck!

0
Harshit Ruwali On

Change the 'categories' variable form 'var' to 'let'.
From,

var categories = [Category]()

to

let categories = [Category]()

Just re-build it and this is working.

0
Gaspare On

I'm following the same lesson. In my case was just an Xcode bug and "Category" was not recognized as a class. I just close and re-open it and work fine.

0
D4vi9 On

If [Category]() is not recognized as a NSManagedOject, just put the term Category between two single reversed quotation marks inside the brackets.

link to example

0
Aaron Yang On

I had the same problem. In my DataModel file, I changed entity name and the class name from "Category" to different one, such as "TodoListCategory." Then in my CategoryViewController, I changed all the Category objects to "TodoListCategory" and rebuild. It solved my problem.

After that, you might have error "Command CompileSwift failed with a nonzero exit code." Now, try to clean your project by using Shift + Command + K & Option + Shift + Command + K

0
Utkarsh Bajaj On

While declaring a array of the type Category, do it like :

var categories = [[`Category`]]()

(if you have the name of the entity as "Category")

note: There is just a single back tick to the left of category.

0
Vitalii Safronov On

Good day!

Please make sure you did not choose Opaque Pointer instead of your Class. See below:

Screenshot

if you did, replace Category with 'Category'

0
aleksandr On

I had same issue while been going through Angela Yu course and I had tried all of the available solution which I could find, but only this one has helped to me: while your project is opened:

  1. press Product on the top pane
  2. press Clean Build Folder

do not use hotkey combination - just press it with your mouse! only this method help to me to get rid of this error.

0
lihuan guo On

We need to change the class Module to "Current Product Module" in inspector on the right

enter image description here

0
Shalini On

Please check on the right side panel, in File Selector if the code generation language has been set to Objective-C. If its Swift change it to Objective-C. Thats how I resolved my issue.