Xcode 9.4.1 and Foundation Framework - xcode

Hello I'm new to programming in Objective-C. I'm reading the book "Programing in Objective-C Developers Library" and they're asking me to create a command line project using the foundation framework, but when I go to create one, I don't see an option to use Foundation.

Your first screen shot shows it:
You've already selected Command Line Tool, which is correct. So now click Next and you will be creating a command line tool that uses the Foundation framework. In your second screen shot, enter a name for the tool and click Next; you will then be asked for a place to Save this project. Do so. When you do, the code for main.m will say:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
}
return 0;
}
See that first line? That is "using the Foundation framework".

One thing to know is that Foundation is so important in Objective-C that it's practically part of the language. It provides classes like NSNumber, NSString, NSArray, NSDictionary, and many others that we assume are always available. So Foundation is special in that every Objective-C project will use it, and it'll be included in any project templates like the Command Line Tool template you're working from. Other project templates will include additional frameworks (e.g. the Cocoa App template will set up your project with AppKit for you), and if you want to use other frameworks you'll add them yourself after you create the project.

Related

Custom templates Xcode to C++ project

I'm going to edit my question.
When I want to developer in C++, I go to:
Xcode => New Project => macOS => Command Line Tools => File C++.
When I edit the main.cpp, the content is to defect (with int main(int argc, const char * argv[])....//More code..).
I create a new templates here (To right of Command Line Tools):
enter image description here
Then, I need to create a new project here:
Library/Developer/Xcode/Templates/Project_Templates/name_group = Applications(for_example)/nametemplate.xctemplate /
Here there are several files:
-main.cpp (my template basic c++)
-TemplateIcon.icns (icon of 128 px)
-TemplateInfo.plist : file configured
But this file I don´t know how modify :(
I´ve tryied to put file templateInfo.plist of this directory: Applications/Xcode.app/Content Packets/Contents/Developer/Library/Xcode/Templates / File Templates / C++....
But Xcode don´t recognize, I know that problem is in TemplateInfo.plist but I don´t know how I can modify :(
Now, Do I explained me better?
Thank you!!

Can't find AppDelegate.m in xcode

I'm currently trying to implement Facebook SDK into my Unity App but I can't find the AppDelegate.m that I must modify in order to implement the SDK.
I tried searching everywhere in my Xcode folder but it seems nowhere to be found.
I search on google too but as I really don't understand anything to Xcode (except from building my Unity Project), I don't understand the answers too...
Thanks, and have a nice day !
The file name “AppDelegate.m” is a generic reference to “the file that contains the definition of your application delegate class”. Your app is not required to name the file “AppDelegate.m” however, so you’ll need to find yours.
Somewhere in your app there is a class that implements the UIApplicationDelegate protocol. You should search for “UIApplicationDelegate” using Xcode’s search function. That should put you on the right track to finding the class. Whichever file that class is in is the file you need to refer to when other documentation says AppDelegate.m
Update:
I forgot that in objective-c you don't declare adoption of a protocol. Here is a different way to find your app delegate.
Find your main.m file (this file is required, so you'll definitely have one). It will contain code like this:
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([YourAppDelegateClassName class]));
}
}
The interesting piece is [YourAppDelegateClassName class], since this represents the class of your application delegate. Do a search for the first word in the square brackets, in this case it is YourAppDelegateClassName.
You can find it by searching UIApplicationDelegate in xcode search, then you will find the implemenation of this protocol in some file named as something.h.that's the file which you needed.
In Xcode 13.3.1 the file would be the (AppName)App file. This file defines the entry point for the app. This file is where you would define the app delegate class.

Xcode 4 plugin development

I've been looking all over the place but I can't find anything. Does anyone know how to create an Xcode 4 plugin?
As far as I know there is no official way to create Xcode 4 plugins (just like there wasn't one for v3.x).
Here is an openradar on Xcode's lack of plugin support:
Please support the ability for 3rd
parties to extend Xcode via a public
plugin API. Aperture, Visual Studio,
Eclipse, TextMate and other
applications benefit from this
ability. I would like to see more
advanced refactorings, code analysis
(think Resharper by Jetbrains) and
modeling.
Provide plugin API for Xcode 4 (rdar://8622025)
Please dupe this if you want plugins!
Edit: Just stumbled upon this:
Cédric Luthi:
"Xcode 4 does support user-defined
plugins, see CLITool-InfoPlist
for an example of a working Xcode 4
plugin. You just have to add
XC4Compatible (true) in the
Info.plist."
https://github.com/0xced/CLITool-InfoPlist
That being said these GitHub repos might be handy, too:
Xcode4 Plugin-API Documentation (link dead)
Xcode Plugin Template (link updated)
Further more mogenerator's Xmod plugin might be a good starting point.
(Wasn't Xcode-4 compatible yet, last time I checked, though)
Best way to learn is to look at github plugin code (see long list below):
Basically its a plugin bundle.
No main.m No MainMenu.xib
First class loaded by setting NSPrincipalClass in info.plist
in its init: you register for AppKit notifications
See the code samples
some check the mainBundle app id to make sure this is XCode
The XCode Editor window class is DVTSourceTextView
Its a subclass of DVTSourceTextView :NSTextView : NSText
so you can register to listen for its notifications for NSTextView or NSText
such as NSTextViewWillChangeNotifyingTextViewNotification
Because its not an official standard I noticed each sample loads in different ways.
XCODE PLUGIN SAMPLES
compiled by either searching github/web for
'DVTSourceTextView'
This is the Xcode Editor window class name
or
Info-list key
'XC4Compatible'
https://github.com/omz/ColorSense-for-Xcode
https://github.com/ciaran/xcode-bracket-matcher
- uses a ruby parser run as pipe!
https://github.com/joshaber/WTFXcode
https://github.com/0xced/NoLastUpgradeCheck
http://code.google.com/p/google-toolbox-for-mac/downloads/list
see GTMXcode4Plugin
https://github.com/DeepIT/XcodeColors
https://github.com/0xced/CLITool-InfoPlist
https://github.com/sap-production/xcode-ide-maven-integration
https://github.com/ciaran/xcode-bracket-matcher
TO GET TO THE NSTextView that is the console
https://github.com/sap-production/xcode-ide-maven-integration
- (NSTextView *)findConsoleAndActivate {
Class consoleTextViewClass = objc_getClass("IDEConsoleTextView");
NSTextView *console = (NSTextView *)[self findView:consoleTextViewClass inView:NSApplication.sharedApplication.mainWindow.contentView];
if (console) {
NSWindow *window = NSApplication.sharedApplication.keyWindow;
if ([window isKindOfClass:objc_getClass("IDEWorkspaceWindow")]) {
if ([window.windowController isKindOfClass:NSClassFromString(#"IDEWorkspaceWindowController")]) {
id editorArea = [window.windowController valueForKey:#"editorArea"];
[editorArea performSelector:#selector(activateConsole:) withObject:self];
}
}
}
return console;
}
Have a look at this new plugin: https://github.com/sap-production/xcode-ide-maven-integration. Maybe you can derive some concepts for your plugin.
Yesterday ColorSense for Xcode 4 was released on Github. Since the code is really compact spread over just 3 classes, I think you should take a look over there.
Xcode does not have a public plug-in API.
This was the case with earlier versions, and is the case with Xcode 4 as well.
No, Xcode doesn't support plugins, alternatively you may try AppCode, another IDE for iOS/MacOS, it does support plugins development.

Xcode: How to find the source code for standard or system libraries?

Xcode question here: If I'm programming in C++ or objective-C, and I #include or #import a library; e.g.
#include <iostream>
#import <Cocoa/Cocoa.h>
I'm often not sure where to look for these header files in the directory structure on my Mac. In other development environments, you can right click the included or imported filename and have the option to jump to source. Is there an equivalent feature in Xcode?
Also, for the standard C++ libraries and the Cocoa framework, is the source code for the implementation files available, or only the headers together with compiled link libraries?
For Apple frameworks, the headers are available. You can also option-double-click on a method or selector to get to either Apple documentation or to the relevant entry in the associated header file.
Holding option and double clicking on a function is a great way to see a document snippit, pictured below. You can hit the book button from there to see the whole documentation item.
But that doesn't have the source. To answer your question, what you might try is the button with the .h on it, pictured above the NSURLConnection.h box, It should pop you into the source for the file displayed in that title.

Bounce the Downloads stack dock icon using C++ (without using ObjectiveC)

Firefox doesn't currently bounce the Downloads box in the dock when a download is finished, like Safari, Chrome and Camino do.
If Firefox was written in Objective C, you could very easily add the one line of Objective C code required to do this. However, it's not. Is there a way to call this Cocoa function from C++ so that it can be added to Firefox for the benefit of all Mac users?
What I'd recommend, and I had to do this for a project I was working on, you could have a few files of obj-c++ that provide both a C/C++ api and internally use obj-c code to trigger the doc flashing.
Essentially you create a standard C/C++ header file. In the code side you make the file a .m or .mm file.
This would then let you write the obj-c one liner in questions directly into a C/C++ function, and since the header file is in plain C/C++ it won't be a compiler error for the non .mm files in the project.
This of course assumes that compiling with a compiler (like GCC) that speaks both languages.
A simple and (tested) example of this approach would be:
TriggerBounce.h
void TriggerBounce(char * filepath);
TriggerBounce.m
#import <Cocoa/Cocoa.h>
void TriggerBounce(char * filepath) {
NSString *pathToFile = [NSString stringWithCString:filepath encoding:NSUTF8StringEncoding];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:#"com.apple.DownloadFileFinished" object:pathToFile];
}
You can use the Carbon API's CFNotificationCenterPostNotification.
Carbon is pure C.
Documentation and code samples here.

Resources