When I was using Xcode 3 I had configured it with a perl script I found on the web that allowed me to automatically generate the #property, #synthesize and dealloc code for new instance variables. Xcode 4 doesn't have that User Scripts menu though.
Is there a way to plug in these kinds of User Scripts for Xcode 4 or does Xcode 4 have a new feature that generates that stuff automatically? (I've looked and can't find one though).
I'm not talking about linking to IBOutlets. I know that I can drag from a xib and it will create all of the right stuff for IBOutlets, but I'm looking for something that will create #property, #synthesize and dealloc code for any instance variable.
Thanks,
Kenny
I would strongly (and I can't emphasize this enough) suggest the application:
Accessorizer
This is by far the most useful application for writing objective-C and objective-C 2.0 code that I have found. Originally written in the pre ObjC2.0 days, it created ivar getters and setters for you. Over the years it just keeps evolving. Now it does properties, container classes, key value encoding, KVO.
It tailors to your style: What line do you put brackets on, how do you indent, how do you comment? It also installs as a service so you can call it up from XCode, copy to the clipboard and paste right back into XCode.
I am not the author, I get nothing for plugging this. However, I have introduced its usage to every Mac team I've worked on and have converted every Obj-C programmer to it on first use.
It's got a demo period. Definitely at least try it out and see if it solves your issue.
I managed to get the Xcode 3 perl script mentioned above working under Xcode 4 as a behaviour.
I put it up on github. https://bitly.com/HXHiij
Hope that helps.
I haven't tested either of these yet, but both claim to support Xcode 4:
https://github.com/CraigWilliams/property_synthesize_dealloc
https://public.me.com/dhoerl (Navigate to Xcode/PropertyMaster)
I also miss the property related scripts, but I have found a workaround. As noted elsewhere, XCode 4 will automatically generate the property/synthesize/dealloc code for IBoutlets that are hooked up through IB.
So I have a dummy XIB in my project called Property_Hack.XIB with some UILabels, and whenever I need a new property for a class I go to Property_Hack, change the owner, and "connect" a label to the file. All you have to do is enter the name of the ivar you want, and XCode will add the #property statement to the .h, and in the .m it will add the #synthesize and dealloc code. Then I modify the .h (delete IBoutlet keyword, and change UILabel to the datatype you want).
Rather hackish and far from perfect, but it is still a time saver compared to the manual effort of modifying both files. Since NSIntegers and BOOLs do not need dealloc code, and are assign instead of retain, I usually set them up manually instead of using this approach. Whether or not NSStrings should be copy or retain is an argument I will not rehash here :-)
Related
So this is just bizarre. If I create a custom Table View Controller as a subclass of UITableViewController, I can't reliably edit the .m file. When I click on it, I can see everything in the file, but I can't actually drop the cursor in to edit the code; it stays fixed in the top-left of the screen. Anything I type will appear, and any code already in .m that happens to be on that line will randomly appear. It's like a static image of the .m contents are on the screen, but the actual text is hidden.
Eventually the entire editor just goes blank. Everything else works fine. I wiped Xcode with app cleaner to pick up all the loose com files, restarted, re-installed Xcode from the dmg and re-created the project and still have the same problem (this is under Mavericks, by the way).
Granted, Xcode 5 doesn't seem to have this issue, but I'm quite new to programming and am following a course that's based on Xcode 4. And at this point the issue is just so stupidly weird that I want to figure out what's going wrong. Any insights?
I've given up. If for some strange reason someone happens on this question and has the same problem, it's not worth the energy; just head to Xcode 5 and live your life bizarre-error free (for now, heh).
I was having the same problem. I just cleaned the Build Folder and everything seems to be working perfectly now. You clean the build folder by selecting Product, hold Alt, and then "Clean Build Folder.
I too had this problem after upgrading to XCode 5, then downloading and installing XCode 4.5 (without removing Xcode 5). What I wound up doing was to create all my new UITableViewController files (File->New File->Objective C Class) as UIViewController files, then modifying the parent class to UITableViewController in the .h file.
I have 2 classes, an NSObject and an NSView. No AppDelegate.
I was getting a hard error "method definition not in #implementation context" even though the methods were between #implementation and #end. Moving a #import ahead of #implementation eliminated that but then variables from the other file were not known. To get rid of it, I wound up // commenting out all the code lines in both .h and .m files. There's no code left except #interfaces, #implementations, and #ends.
I still get a warning "#end must appear in implementation context." One of them appears immediately after the #end!
I have not attempted to use IB in this program.
Other programs compile correctly, and I think the code is correct in his one and it should work.
Is there some way the compiler gets stuck? OSX 10.6.8, Xcode 3.2.6.
I gave up on that project, created a new project, and copied and pasted the text from the bad one. The new project works fine with the same old text.
Then I ran memtest repeatedly and Applejack to clean up. The hardware is ok.
Probably the compiler is flaky; I've had to do this a couple times this year. Last time an error message said that the compiler had a partition problem; Google links said to upgrade and maybe the new version would fix the problem. So I installed Xcode 3.2.6, which produced the same error, unfortunately. Copy and paste to a new project was necessary, again.
today I came across a strange problem.
I started a really simple project where I just had one View with an UITextField on it. During execution of program I wanted to set the text of that TextField but I figured out that UITextField only was referenced to 0x000000.
Of course before I had correctly connected the Outlet to the TextField as I always do - I have got many experiences in working with Xcode and iOS and did it really often before.
I tried everything from deleting the TextField again, creating a new outlet by the help of interface builder or even deleting every peace of code and doing everything from the very beginning. But nothing did work.
Because I did not understand it I created a new project and although I did everything in the same manner this time it worked.
Unhopeflly after many many lines of code I added a second view and now I've got the same problem with this second view.
Does anybody now, what I'm doing wrong?
If you need some kind of code, let me know, but believe me, I really just created a new view, put another TextField on it, created the outlet via Xcode and then pressed run. Then I set a breakpoint in the viewDidLoad method and here you are: TextField only is referenced to nil.
Please help me if you have any ideas.
Is there anyway to make xcode (4.2) automatically add synthesize and the empty method bodies to the implementation file (for properties and methods defined in the interface) ?
There is no built in solution for that in 4.2. You could try creating a shell script that searches your header for properties and then adds the #synthesize lines at the right place.
Why don't you use the latest (4.4) version instead? 4.4 can automatically synthesize the ivars for you. All you have to do is declare a #property and Xcode takes care of the rest.
This is a real 'WTF?' moment for me.
I copied some classes out from another project, including copy and pasting the code and some UIBulder components. What did NOT get copied was the XIB file (I went from XIB to storyboard).
My tab / swipe recognizers aren't activating, and when I drill down the only thing I can discover that can explain it is that somehow, someway, I'm hooking up against the XIB file. (When I click on the little button next to the IBAction/IBOutlet lines in the header, it shows me both the storyboard and the xib file as connected).
I'm not referencing that file anywhere that I can find, it's just somehow magically recognized in Xcode. I don't know what to do, how to fix this.
Anyone have any ideas?
Edit: The really annoying bit is that the file doesn't appear to be in my files list when I check there, I can't just delete the reference that way. And since it's referencing the file in the original project, I can't just delete it. (Any changes made in either project cause changes in BOTH projects; their both using the same xib file for some reason). I should be able to simply delete the reference to the xib file, but I can't find the reference.
If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets.
If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.
Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Right click your views in the storyboard to see what referencing outlets really exist in the current project. (See my fuller answer for more details.)
No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior.
The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore the little circle.
I just had the same problem. What solved it for me was to close both projects, delete the derived data from both and then reopen the destination project.
I agree, it's a crazy problem.
I'm sure that this problem could happen and I fix it deleting the content of the Derived data folder of XCode.
I just want to add the steps of how to delete those files:
Don't Delete the DerivedData folder.
Go to preferences (Command ,) > Locations Tab
On Derived Data you are going to see the path, clic the right pointing arrow (that will open that location in Finder)
Close XCode
Select all the files inside the DerivedData Folder (do NOT select parent folder) and (Command Delete) or move them to the Trash and then Empty Trash
Open the project and you are done
I hope it helps someone
unless the xib file is in the project. it should not have a link to it.
the xib file connects to the .h file. not the other way around.
You may want to remove the connections in the storyboard and re-connect them.
Also make sure that the storyboard is the UI being started and that the item on the navigation stack is actually the storyboard page. But you should be able to connect both the storyboard and the xib file to the class at the same time. You just cannot connect one IBOutlet to more than one object in a single ui component (e.g. two buttons on the storyboard cannot both be connected to #property IBOutlet UIButton *myCurrentButton you must have a separate IBOutlet for each connection. On the other hand, any number of actions can be connected to an IBAction. which is why you get (id) sender on each action.
I dont know if this is exactly what you are experiencing, but I hope that understanding helps you debug your issue.