How to use Fragaria Framework in Objective-C? - objective-c

I am trying to get Fragaria to color / Sytax highlight my Scring, but it doesnt work,
I create a blank new Project
Add the Fragaria Framework (it works)
add a custom View in Interface Builder and set its Class to MGSFragariaView
I create an Outlet, call it editor.
i also add this line because i saw it in other Samples:
#class MGSFragariaView;
Now i try to config the editor like this:
_editor.syntaxDefinitionName = #"Shell";
NSString *source = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"sh"];
NSString *code = [NSString stringWithContentsOfFile:source encoding:NSUTF8StringEncoding error:nil];
_editor.string = code;
[_editor setSyntaxColoured:YES];
But no matter what i try, the Code does not highlight, it remains simply black with no errrors or warning, why?
What am i missing?

Nevermind, Fragaria worked as expected, i was using a fork from Microsoft, it seems there were some issues with Dark Mode on MacOS coloring the ttext

Related

'Show Package Contents' through objective C code

We can right click an .app file and see its package contents. To open a file programmatically, we can use NSWorkspace but how to open the app's package contents?
I have searched a lot but seems there is no solution. Please help if I am missing something.
Per the comment it seems the OP want to open the contents directory of an app in the finder from code. The following line will accomplish that:
Swift:
let appName = "Safari";
let command:NSString = String(format:"open '/Applications/%#.app/Contents'", appName);
system(command.cStringUsingEncoding(NSUTF8StringEncoding))
Objective-C:
NSString *appName = #"Safari";
NSString *command = [NSString stringWithFormat:#"open '/Applications/%#.app/Contents'", appName];
system([command cStringUsingEncoding:NSUTF8StringEncoding]);
Alternate:
NSString *appPath = #"/Applications/Safari";
NSString *command = [NSString stringWithFormat:#"open '/%#.app/Contents'", appPath];
system([command cStringUsingEncoding:NSUTF8StringEncoding]);
This seems to work:
NSString* contentsPath = [appPath stringByAppendingPathComponent:#"Contents"];
[[NSWorkspace sharedWorkspace] selectFile: contentsPath
inFileViewerRootedAtPath: appPath];
An application is just a directory, show package contents just allows you to access the application as a directory rather than executing it. So you can access a file within an application such as
/Applications/Safari.app/Contents/Info.plist

how to get version of default browser on my mac os x

I want to get system information in mac using objective C.
I am searching a lot but did not got single line of code for
my use.They provided solutions via javascript but i want them in
objective C.
Provide me some help to go ahead.
You can use launch services to get the path to the default browser as below
LSGetApplicationForURL((CFURLRef)[NSURL URLWithString: #"http:"],
kLSRolesAll, NULL, (CFURLRef *)&appURL);
NSString *infoPlistPath = [[appURL path] stringByAppendingPathComponent:#"Contents/info.plist"];
Now read the CFBundleShortVersionString from the info.plist.
Here you go :
NSString *userName=NSUserName();
NSLog(#"UserName: %#",userName);
NSArray *ipAddress=[[NSHost currentHost] addresses];
NSLog(#"IP Address=%#",ipAddress[0]);
Updating my answer
This is tested and works well
NSWorkspace *nsSharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *nsAppPath = [nsSharedWorkspace fullPathForApplication:appName];
NSBundle *nsAppBundle = [NSBundle bundleWithPath: nsAppPath];
NSDictionary *nsAppInfo = [nsAppBundle infoDictionary];
//Now you can print all dictionary to view all its contents and pick which you want
NSLog(#"%#",nsAppInfo);
//or you can get directly using following methods
NSLog(#"%#",[nsAppInfo objectForKey:#"CFBundleShortVersionString"]);
NSLog(#"%#",[nsAppInfo objectForKey:#"CFBundleVersion"]);
Dont forget to add AppKit framework

How do you set what about:home is on webView, Obj-C

I am creating a Cocoa web browser, and I noticed that if the webview loads a nil location, it just loads about:home. Since I have not set it, the page just appears white. Is there a way I can change what about:home looks like. Even if it is a simple .rtf file or something.
I looked around, but don't see any way to do this. Am I suppose to create a NSURL and set it to whatever file?
Thanks. Oh, and if code is ever needed, I would be glad to add it.
Try something like this:
// Inside your App Delegate
-(void)applicationDidFinishLaunching:(NSNotification *)notification {
// Assuming WebView is called myWebView
NSString *currentURL = [myWebView mainFrameURL];
if(!currentURL) {
NSString *homeResource = [[NSBundle mainBundle] pathForResource:#"home" ofType:#"html" inDirectory:#"default"];
NSURL *homeURL = [NSURL fileURLWithPath:homeResource];
NSURLRequest *request = [NSURLRequest requestWithURL:homeURL];
[myWebView loadRequest:request];
}
}
You'll need to have a pre-made file called home.html within a folder called default located in the Resources section of your project.
I suppose this isn't exactly replacing about:home, but you can always check for about:home and handle that appropriately as well.

What does it mean by references?

I'm taking a tutorial for X-code that says this:
"Go into the code and change the references from DrinkArray to DrinksDirections."
What exactly does it mean?
I would show you the tutorial, except it's a book that costs money.
The only reference I found of DrinkArray is:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"DrinkArray" ofType:#"plist"];
NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
self.drinks = tmpArray;
[tmpArray release];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
"Reference" is not a precise technical term in Objective-C, so what it means is whatever the author meant was thinking of when he wrote it. The term is sometimes used in "passed by reference" or "returned by reference," in which case "reference" means "pointer" — but that doesn't seem to be the usage here. Most likely the tutorial means to change places where your code mentions "DrinkArray" to instead say "DrinksDirections."
This is from Head First iPhone Development. The code in viewDidLoad that you found is where you want to make the change:
NSString *path = [[NSBundle mainBundle] pathForResource:#"DrinkArray"
ofType:#"plist"];
This line basically asks for the file path to the DrinkArray.plist bundled with the application. In the tutorial the next step is to migrate to a dictionary based array where each element contains a name, ingredients and directions.
Rather than typing out each entry by hand, they've provided a copy of the updated plist named DrinkDirections.plist in the book downloads. After downloading the sample files, copy the DrinkDirections.plist into your project Resources folder. Then change the line in viewDidLoad to
NSString *path = [[NSBundle mainBundle] pathForResource:#"DrinkDirections"
ofType:#"plist"];
This asks for the path to the DrinkDirections.plist that you've just added to your project. Be aware that your application will crash after making this change - that's OK, it's part of the tutorial and is covered in the immediately following pages.
okay, I figured it out. It wasn't DrinkDirections, it was DrinksDirections. It's stupid that a little thing can mess up a whole program.
The type of some declared reference variable is DrinkArray. It's telling you to change the type to DrinksDirection. Can you paste the code snippet?

best way to get text from a plain .txt file into a Scroll View

Can someone please help me out with this I'm actually going nuts!
What is the best way to get text from a plain .txt file into a Scroll View, thats all I need just text.
I've tried so many different solutions but can't get any of them working I was hoping someone could give me a fresh overview.
Is the file a resource in your application or are you loading it from a network resource? If embedded, you can load it into an NSString object and then set the text property of the UITextView with that. Something like:
UITextView *myTextView = [[UITextView alloc] init];
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:#"yourTextFile" ofType:#"txt"];
NSString *theText = [NSString stringWithContentsOfFile:pathToFile encoding:NSUTF8StringEncoding error:nil];
myTextView.text = theText;