Im using XCode 4 and working with CoreData. Now, how do I generate classes for entities? I used to do it in XCode 3 by clicking on a diagram entity, going to File->New and choosing NSManagedObject class.
For some reason i cant seem to find it in XCode 4, it's not showing up in the dialog...
If you are new to Xcode (like me) some graphics to make it easier to explain. Just make sure that you select the entities that you want before you click on "Create NSManagedObject Subclasss"
You'll find in DP5 it is now a menu item. Finally!
I got it working by making the entity CLASS the same as the entity NAME, i.e. "Person" instead of "NSManagedObject". I also noticed that I have to invoke File > New File twice (!) The first time, the Managed Object Class template is not available, but the second time it is. No clue why.
I'm running XCode 3.2.4.
While editing your xcdatamodel you need to select the entity and make sure the right hand Utilities pane is open. Select the Data Model Inspector (the tab on the right) and you can set the class of your entity to whatever you want.
Related
I've just installed mogenerator using one of tutorials. I have added run script to my new target, and clicked Cmd+B. I should get some new files, but i didn't. In my .xcdatamodeld i have 2 entities (User and Repos). Below you can find my print screen of my project.
Where is the problem in my thinking? What should i do more? Please, help me, because i haven't found the solution on the web yet.
This all looks fine (judging by your screenshot).
One thing to check - which caused me the same issue - is that, when you've created your Entities in the xcdatamodelId file, make sure that you click on the Data Model Inspector icon, and that each entity has a Name value, and a matching "Class" value.
Miss out the Class name, and nothing will get generated.
Btw, when you click on Build, do you get a "Build succeeded" message ?
Here's the tutorial I followed to get mogenerator working:
RaptureInVenice
I should say, I've used mogenerator in a few projects, and this command line bit is always the piece that gives me trouble. Sometimes, I have to select my xcdatamodelId file, and create a new Version of it, before mogenerator will use it. But once it is working, it's a blessing.
Anything to avoid having to use the needlessly over-complicated CoreData stuff.
Someone should remind Apple that it's 2014...
I am new to objective C development. In inherited someone else's project.
I see that in his project, he has a folder called Model. In it are the files
Product.h
Product.m
Compatible.h
Compatible.m
Model.h
Model.m
MyProject.xcdatamodeld
A few days ago I created two new files called Warehouse.h and Warehouse.m, following the style of coding I saw in Product.h and Product.m. I also wrote some functions in Model.h and Model.m that helped me grab new Warehouses. I then created a new Entity in MyProject.xcdatamodeld by opening that file up in XCode, clicking Add Entity, renaming the entity and adding the necessary attributes.
I was able to use this new class/model in the rest of my project.
Today, i decided to add some new properties to my Warehouse.m. I then added new attributes to the MyProject.xcdatamodeld by clicking on the new attribute buttons.
Now my project crashes right when it starts up, giving me the error Can't find model for source store.
Am I doing something wrong? I vaguely remember someone telling me it's a headache of the model changes. Can someone recommend me reading on the subject matter? And how i can fix my situation?
I went to MyProject.xcdatamodeld. Then clicked on "Configuration" in the left navigation. Then I noticed a table showed up with the following contents:
Entity Abstract Class
Compatible un-checkbox Compatible
Product un-checkbox Product
Warehouse un-checkbox
I noticed that the Warehouse row didn't have a value for Class. So i typed in Warehouse in to it. Then everything worked.
I already asked this in the Apple Dev Forum but received no replies, so I'll try here.
I'm unsure if this is a bug or whether I've missed something since I'm still very new to programming.
I have multiple view controllers and have made multiple classes. I have set the custom class "bit" of each view controller to the revelent class. When I ctrl-drag anything from the view to the relevent class header, I get the usual pop-up. I fill in the info, press connect, and BAM. It does the same kind of error whether I choose "Outlet" or "Action" It worked in the previous Xcode but I'm not sure if I've forgotten something.
The view controller and class that I added with Xcode 4 is still working beatifully.
I've tried adding the image manually but all that gave me was a SIGBART error just trying to get to the view. Again, I may have missed something, but I don't think there's much to miss is there?
Any help would be appreciated.
Just to eliminate a few things... I've deleted derived data, restarted Xcode and done a "clean". That's all I can remember that I've done.
Problem solved:
When selecting the implementation file. When I looked in the File Inspector, I found that under "Target Membership", the app name wasn't ticked. I ticked it and it now works well.
Since I didn't need to do that in Xcode 4, I suspect in Xcode 5, it doesn't do that automatically. Maybe that's a bug? I don't know if it was deliberate by Apple, but I think I'll file a bug report anyway since It's a bit of a nuisance.
I think that looking at others' code is a good way to learn. I'm trying to learn iOS programming like this, but one thing that's confusing is when I look at a new project there's always a bunch of view controllers, and I don't know which one loads first.
Is there an entry in the plist file which says which view controller gets loaded first? How do you go about picking apart someone else's code in an Xcode project?
In the project there's a space called Main Interface / Main Storyboard that looks like this:
Target > General > Deployment Info > Main Interface:
But if they set it in code, then use ⇧+⌘+F on the project and search for 'rootViewController'.
How I can create a code in XCode 4.2.1 what will create NSTableView and add just couple of items to it?
All what I wanted to do is:
1) Window where is NSTableView
2) I have an array of strings in NSArray which I like to show in that NSTableView
3) All of this should be done in code. So I don't want to learn how to add this action happen when you press button (I know already how to do actions when user click buttons etc), I just want that application launch -> draws the table where is those items from my array. That's it, nothing more.
And yeah I have understood that I do not add items to NSTableView directly. That is not the point in this question. I just mean that I want to show couple of items in that table but I have no and kind of clue WHERE I should add my data from my array.
I have tried to google for example pages for hours (just too many and have not find help) but I will always be stucked in the part when
a) I must do something in the Interface Builder and the images of the interface builder are from version 2.x or 3.x and I have 4.2.1 and it is totally different (new to XCode...). Surely I have drawn my TableView element to UI but I mean delegations etc. Are those necessary at all? Can those be made from source code?
b) Code just does not work anymore because language (Cocoa or Objective-C, I don't know) has changed and I don't know how and what I have to do to make it work on newest version of XCode.
c) There is too much different ways told: "use binding", "you must create new class what is NSTableViewDataSource" etc. I have no any kind of clue what is preferred way, is another way optional or it is "you should use this because another is going deprecated soon" or something.
So please, can somebody give help in step-by-step what I exactly have to do? Should I create some bindings? If so, how and where? Do I have to create DataSource component myself? Are those ways valid any more? If I have to, how I can create it? Create a new class and implement it as a NSTableViewDataSource and then use it? Is that way valid any more and if it is, can sombody show code what is as simple as possible?
I have also checked Apple Documentation page many many times, checked those example codes but there is just too much totally unrelated stuff that I just don't understand at this point so they are totally useless (I mean, I don't know what is required for this task, what are not etc.
I would be very happy if somebody can help short tutorial step-by-step what to do. I mean "step-by-step" like:
1) Create new project
2) Draw NSTableView in project
3) Create new class with this name
4) Write this code: blah blah blah
5) Create another class with this name
6) Write this code
7) Run and see those items from array in NSTableView using (bindings/datasource/whatever is preferred).
Thanks :)
Your tableview needs a datasource. Your datasource is a custom class, it implements the "NSTableViewDataSource" protocol. This protocol contains a few methods that you can use to tell the tableview what data you got.
this includes the objectValue ( the value of the NSCell that is displaying your data on the specified row, and a method that returns the amount of rows the tableview has ( the amount of items in your array ).
Here a tutorial I found by googling:
CocoaDev.com NSTableView tutorial
You can also implement the NSTableViewDelegate protocol which allows some greater control. Like what rows you can select, or some extra configuring of a custom tableview cell.
I must say that back in the day when I started developing desktop applications ( only had experience with web technologies ) that this design pattern confused me as well. Hope you will get your mind round it soon.