Saturday, September 25, 2010

Mac Coder is looking for contributers

Hey everyone!!!

It's been a WHILE since I've touched Objective-C as a college guy. I abandoned it for C#.NET because of job requirements. I don't want this blog to die, and I would like to see more stuff on it, but since I have no free time to continue with Objective-C, I would like to find someone who can!

I would like to know if there's anyone out there who is actively working with Objective-C who would like to help with the contributions to this blog!

Friday, August 24, 2007

Need to make a correction

Okay, if you look backwards in the history of this blog, I've said before that when you use the '*' before the variable name, that tells the compiler to create it in memory. I was a little off by that. What that '*' means is simply reference the pointer in memory. Using this prevents the computer from lugging around a variable from method to method so it can be used. By referencing the pointer, you are essentially lugging around a simple memory address that the method will use to get the value of that variable.


This essentially is saying (Figuratively of course):
I have a car but it's in the garage. If you want to see my car, lets go out to the garage, but I don't personally carry my car with me at all times.


Just thought I would clarify this Objective-C/C++ thing.
Happy Coding :-)

Tuesday, August 14, 2007

Running an application as root in Objective-C

Okay, so if you look back into the past a bit on the Blog history, I was having problems with this type of thing. I had an application that needed to access files belonging to root. Anyway, after 2 1/2 hours reading documentation, I found this code snippet.

AuthorizationRef authorizationRef;

AuthorizationExecuteWithPrivileges(authorizationRef, "/Path/To/Application.app/Contents/MacOS/Application", kAuthorizationFlagDefaults, nil, nil);

Now, this will run any application as a root user so use it wisely. Just make sure, if you are trying to run a .app file, you need to continue into it's contents and run the actual application. That's represented above. Just replace both "Application" instances with your application's name.

After the call is made, the OS will launch the application specified with root user privileges. It will require that you authenticate as an admin before the application is launched.

Killing a process by name in Objective-C

Okay, so one thing that really frustrated me was that in objective-c, there wasn't a way to kill a process by name. Well, I found the way to do it. There is a command line application that you can use to kill a process by its name. To use this in Objective-C, you just need to use the following.

system("usr/bin/killall processName");

If you want to make this dynamic created using a NSString, just make sure you call the cString function on the NSString object.

Thursday, August 9, 2007

I need some help!

Okay. So, if you are a UNIX genius, you might be able to help me with this.

I have an application that uses the system() command to send a command to the terminal. I'm using sudo to allow the user to delete files that belong to root.

so an example will be something like this
system("sudo rm /file/to/delete.txt");

But, as soon as this runs, it asks in terminal for a password.

Here's the thing. I need it so that all authentication is done without the terminal. It all needs to be handled in the objective-c application.

Is there a way to pre-authenticate the user so that sudo will work without asking for a password in terminal? Is there another way to delete files that belong to root in objective-c? If you can answer this, please help me out. That would be great!

Saturday, August 4, 2007

What to do next!

So, I think I answered, for the most part, everyone's questions I've received. Now, what else is there that you are having problems with? (Objective-C problems, not life problems)

I'm thinking about placing a post up about Localization. Would anyone be interested in that? It's really hard to explain in the blog so it will be a download the source kind of thing. But, if you are working with a big company that does business around the world, then localization will be something you will have to deal with. 

I'm can't really think of anything else right now to create or talk about so if y'all have any questions about objective, make a comment to this post. I'll receive an email and respond to the comment ASAP.

Thursday, July 26, 2007

Saving data using NSDictionaries

Okay, I had a blog viewer inquire about this problem. They were wanting to save information about people in a single XML file but didn't know how to do it. 

If you want to save information about people, the easiest way to do that is by using nested dictionaries where a single root dictionary contains dictionaries with your data. 

When you store all your dictionaries in a root dictionary, you can just write the root dictionary to file and and you will get an XML file representation of you data. 

I have a demonstration app up on the server, you just can't find it from the first page. 

Here is the link to the dictionary example to demonstrate how you do this. 
maccoder.server.googlepages.com/DictionaryExample.zip
Make sure you build it in XCode first before you run it. The current built file doesn't reflect a change I made in code to keep it from locking up your computer. 

I hope this helps!
Happy coding! :-)