Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 8, 2013, 03:52 PM   #1
RookieAppler
macrumors member
 
Join Date: Mar 2012
Saving a cocoa application to like an executable.

Hello, I am very new to mac cocoa applications. I currently work on iOS programming. So i was interested in cocoa applications also. I followed few tutorials and got a core-data based cocoa application built. Its very simple. Add records to table view and removing them. Now i have started to compare .net application to cocoa application..is it right?i built C# applications in the past in my school. I used to get .exe files in those applications. I can use the .exe file on any of my PCs. I used archive to create an application to test now. So i saved it on my desktop. Now i open the application and work with it..add records, remove records. When i close the application, it asks me to save it in binary,sqlite or xml. How can i close the application to save it like a .exe file. Basically not to ask user to save..more questions coming. Thanks

Last edited by RookieAppler; Feb 8, 2013 at 04:56 PM. Reason: Changed information
RookieAppler is offline   0 Reply With Quote
Old Feb 8, 2013, 06:16 PM   #2
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
The Binary, XML and sqlite are the data part of core-data. They have nothing to do with (.exe) equivalency.

When you build an (Cocoa) application bundle in MacOS you are creating a nested folder structure with the binary (no file extension) and any resources needed to run that application.

This would be equivalent to creating and installing an application in Windows that includes a .exe and resources like images that are used by that .exe in say C:\Program Files\
jared_kipe is online now   1 Reply With Quote
Old Feb 8, 2013, 08:33 PM   #3
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@jared_kipe.Thanks. So is there a way i can build a cocoa application exactly like an .exe file with resources like you said. Like an application where i enter username, password. It connects to a web service. Validates those credentials and returns me true/false. I want to take that application and put it on my friends mac and he can put his credentials and check. But no saving option when we close the application. Very simple one. I must say again i am very new to cocoa.
RookieAppler is offline   0 Reply With Quote
Old Feb 9, 2013, 06:49 AM   #4
Nmx-
macrumors newbie
 
Join Date: Apr 2011
nwm. didnt quite understand your first post
Nmx- is offline   0 Reply With Quote
Old Feb 9, 2013, 11:00 AM   #5
Ap0ks
macrumors regular
 
Join Date: Aug 2008
Location: Cambridge, UK
Quote:
Originally Posted by RookieAppler View Post
@jared_kipe.Thanks. So is there a way i can build a cocoa application exactly like an .exe file with resources like you said. Like an application where i enter username, password. It connects to a web service. Validates those credentials and returns me true/false. I want to take that application and put it on my friends mac and he can put his credentials and check. But no saving option when we close the application. Very simple one. I must say again i am very new to cocoa.
Turn off core data and document-based application and you'll be able to make a simple program without asking you to save when exiting.
Ap0ks is offline   0 Reply With Quote
Old Feb 9, 2013, 12:37 PM   #6
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by RookieAppler View Post
@jared_kipe.Thanks. So is there a way i can build a cocoa application exactly like an .exe file with resources like you said. Like an application where i enter username, password. It connects to a web service. Validates those credentials and returns me true/false. I want to take that application and put it on my friends mac and he can put his credentials and check. But no saving option when we close the application. Very simple one. I must say again i am very new to cocoa.
You don't understand, every time you build a Cocoa application you are building the 'like .exe with resources like I said'.

What is happening is that you made an application like TextEdit. You go into it, mess around, and low and behold, the application wants to save your progress.

If you want an application without any of that, start over with a pure view based applications, throw some IBOutlet text fields up there with a button to process the results. When you build it you can take that, zip it up and put it on your friends computer no problem.
jared_kipe is online now   1 Reply With Quote
Old Feb 9, 2013, 03:48 PM   #7
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
Quote:
If you want an application without any of that, start over with a pure view based applications, throw some IBOutlet text fields up there with a button to process the results. When you build it you can take that, zip it up and put it on your friends computer no problem
I followed like you said.Doing that will build me a iPad/iPhone application. I dont want an iOS application. A mac/cocoa app that one logs in and gets connected to a web service. A stand alone application.
Forgive me for this non-mac terminology.
RookieAppler is offline   0 Reply With Quote
Old Feb 9, 2013, 04:16 PM   #8
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@jared_kipe.I was also trying to do more on a core data cocoa app (TestApp) that i built. I made an archive->application and saved the file to my desktop. I had saved some data in that application. Saved it in binary info called "PlayerInfo". I launched the app on my desktop. I went to File->Open Recent and choose the binary info file "PlayerInfo". It open another instance of my app TestApp and showed the file info there. So coming back to one my earlier questions, when i double click and open the application can it retrieve the file info automatically?
RookieAppler is offline   0 Reply With Quote
Old Feb 9, 2013, 07:20 PM   #9
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by RookieAppler View Post
I followed like you said.Doing that will build me a iPad/iPhone application. I dont want an iOS application. A mac/cocoa app that one logs in and gets connected to a web service. A stand alone application.
Forgive me for this non-mac terminology.
Sorry, I guess I just mean OSX->Cocoa Application, then don't check off 'Use Core Data'. This will give you a basic view based application.

----------

Quote:
Originally Posted by RookieAppler View Post
@jared_kipe.I was also trying to do more on a core data cocoa app (TestApp) that i built. I made an archive->application and saved the file to my desktop. I had saved some data in that application. Saved it in binary info called "PlayerInfo". I launched the app on my desktop. I went to File->Open Recent and choose the binary info file "PlayerInfo". It open another instance of my app TestApp and showed the file info there. So coming back to one my earlier questions, when i double click and open the application can it retrieve the file info automatically?
There are a lot of ways to answer this. You could use a NSUserDefaults to save all of your data. You could use NSUserDefaults to store the last file saved. You could use NSBundle to save/load your data automatically inside your application bundle...
jared_kipe is online now   1 Reply With Quote
Old Feb 9, 2013, 08:06 PM   #10
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
Quote:
Sorry, I guess I just mean OSX->Cocoa Application, then don't check off 'Use Core Data'. This will give you a basic view based application.
Don't check off? Should i or should i not check the checkmark.? So in one of my iOS app, i check login for an employee. Then save the employee entity in core data. Next time if my app is launched i bring the saved values and use those values to check login. I tried to that here in cocoa, but it was not possible. I used managedobjectcontext to save like i did in core data in iOS application

Code:
ITMLoginResult *loginResult = (ITMLoginResult *)[self.theParser.loginResultArray objectAtIndex:0];
		NSLog(@"the empid gotten is %@",loginResult.empID);
		NSLog(@"the secure hash is %@",loginResult.secureHash);
		
		NSError *fetchError = nil;
		NSFetchRequest *fR = [[NSFetchRequest alloc]init];
		fR.entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.moc];
		
		fR.predicate = [NSPredicate predicateWithFormat:@"employeeID == %@",loginResult.empID];
		NSArray *tmpArray = [self.moc executeFetchRequest:fR error:&fetchError];
		
		NSLog(@"the tmpArray count is %d",tmpArray.count);
		if (tmpArray.count == 1)
		{
			Employee *empl = [tmpArray objectAtIndex:0];
			NSLog(@"the employee exists %@",empl.employeeID);
			NSLog(@"the secure hash for him is %@",empl.empHash);
		}
		
		int empID = [loginResult.empID intValue];
 
		Employee *emp  = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee"																		inManagedObjectContext:self.moc];
		emp.employeeID = [NSNumber numberWithInt:empID];
		emp.empHash = loginResult.secureHash;
		
		[self.empArray addObject:emp];
		
		NSError *error;
		
		if (tmpArray.count ==0)
		{
			if(![self.moc save:&error])
			{
				NSLog(@"Failed to save the object");
			}
			else
			{
				NSLog(@"Save Successful");
			}
			
		}
So i parse an xml and save the values to an array "loginResultArray". I retrieve the same empID if it exists, but tmpArray is always 0. Then i save it using self.moc. I see the message "Save Successful".So whats happening to my data?
RookieAppler is offline   0 Reply With Quote
Old Feb 9, 2013, 08:53 PM   #11
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by RookieAppler View Post
Don't check off? Should i or should i not check the checkmark.? So in one of my iOS app, i check login for an employee. Then save the employee entity in core data. Next time if my app is launched i bring the saved values and use those values to check login. I tried to that here in cocoa, but it was not possible. I used managedobjectcontext to save like i did in core data in iOS application

Code:
ITMLoginResult *loginResult = (ITMLoginResult *)[self.theParser.loginResultArray objectAtIndex:0];
		NSLog(@"the empid gotten is %@",loginResult.empID);
		NSLog(@"the secure hash is %@",loginResult.secureHash);
		
		NSError *fetchError = nil;
		NSFetchRequest *fR = [[NSFetchRequest alloc]init];
		fR.entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:self.moc];
		
		fR.predicate = [NSPredicate predicateWithFormat:@"employeeID == %@",loginResult.empID];
		NSArray *tmpArray = [self.moc executeFetchRequest:fR error:&fetchError];
		
		NSLog(@"the tmpArray count is %d",tmpArray.count);
		if (tmpArray.count == 1)
		{
			Employee *empl = [tmpArray objectAtIndex:0];
			NSLog(@"the employee exists %@",empl.employeeID);
			NSLog(@"the secure hash for him is %@",empl.empHash);
		}
		
		int empID = [loginResult.empID intValue];
 
		Employee *emp  = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee"																		inManagedObjectContext:self.moc];
		emp.employeeID = [NSNumber numberWithInt:empID];
		emp.empHash = loginResult.secureHash;
		
		[self.empArray addObject:emp];
		
		NSError *error;
		
		if (tmpArray.count ==0)
		{
			if(![self.moc save:&error])
			{
				NSLog(@"Failed to save the object");
			}
			else
			{
				NSLog(@"Save Successful");
			}
			
		}
So i parse an xml and save the values to an array "loginResultArray". I retrieve the same empID if it exists, but tmpArray is always 0. Then i save it using self.moc. I see the message "Save Successful".So whats happening to my data?
A lot about this doesn't look particularly right (and wouldn't compile in its current state). At this point, I honestly don't know if/why you want to use Core Data. How much data you are storing, and where/how it is being store in CD.

Submit full compilable code with comments for further help.
jared_kipe is online now   1 Reply With Quote
Old Feb 9, 2013, 10:15 PM   #12
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@jared_kipe. This compiles. I have button click event. On clicking it i connect to a web service. Pass my values. Check login. Return 2 values. empid and secure hash.

Code:
- (IBAction)btnLoginClick:(NSButton *)sender
{
	if (!self.appDelegate)
	{
		self.appDelegate = (ITMAppDelegate *)[[NSApplication sharedApplication] delegate];
	}
	self.moc = self.appDelegate.managedObjectContext;
	
	if (!self.moc)
	{
		NSLog(@"Empty moc");
	}
	else
	{
		NSLog(@"the MOC is not empty");
	}
	NSString *uname = [self.txtUserName stringValue];
	NSString *pwd = [self.txtPassword stringValue];
		
	NSString *path = @"http://abcdxyz.com/IOrderItems.asmx/";
	NSString *strPath = [NSString stringWithFormat:@"%@%@?strUserName=%@&strPassword=%@",path,@"LoginEmployee",uname,pwd];
	NSLog(@"the path is %@",strPath);
	NSURLRequest *url = [NSURLRequest requestWithURL:[NSURL URLWithString:strPath]];
	NSData *dataReturned = [NSURLConnection sendSynchronousRequest:url returningResponse:nil error:nil];
	NSXMLParser *xmlparser = [[NSXMLParser alloc]initWithData:dataReturned]; //newNSData

	
	NSString *requestPath = [[url URL] absoluteString];
	NSString *newString =[NSString stringWithUTF8String:[dataReturned bytes]];
	NSLog(@"the new string is %@",newString);
	
	self.theParser = [[ITMParser alloc] initParser];

	
	[xmlparser setDelegate:	self.theParser];
	
	BOOL worked = [xmlparser parse];
	if(worked)
	{
//..all the code that i pasted earlier
		
	}
	else
	{
		NSLog(@"IT did not work");
	}
}
Yes i want to use CD. Further down in the process of this application, i want to retrieve customer data from web service and store it in CD . Like a complete employee table with 5/6 fields. Customer table with 8/9 fields. So they could be 10000 records. So i will very much use CD in storing and fetching. This is a simple start up. Hope you get my point. Thanks.

Last edited by RookieAppler; Feb 9, 2013 at 10:27 PM. Reason: added some information
RookieAppler is offline   0 Reply With Quote
Old Feb 10, 2013, 02:13 PM   #13
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by RookieAppler View Post
@jared_kipe. This compiles. I have button click event. On clicking it i connect to a web service. Pass my values. Check login. Return 2 values. empid and secure hash.

Code:
- (IBAction)btnLoginClick:(NSButton *)sender
{
	if (!self.appDelegate)
	{
		self.appDelegate = (ITMAppDelegate *)[[NSApplication sharedApplication] delegate];
	}
	self.moc = self.appDelegate.managedObjectContext;
	
	if (!self.moc)
	{
		NSLog(@"Empty moc");
	}
	else
	{
		NSLog(@"the MOC is not empty");
	}
	NSString *uname = [self.txtUserName stringValue];
	NSString *pwd = [self.txtPassword stringValue];
		
	NSString *path = @"http://abcdxyz.com/IOrderItems.asmx/";
	NSString *strPath = [NSString stringWithFormat:@"%@%@?strUserName=%@&strPassword=%@",path,@"LoginEmployee",uname,pwd];
	NSLog(@"the path is %@",strPath);
	NSURLRequest *url = [NSURLRequest requestWithURL:[NSURL URLWithString:strPath]];
	NSData *dataReturned = [NSURLConnection sendSynchronousRequest:url returningResponse:nil error:nil];
	NSXMLParser *xmlparser = [[NSXMLParser alloc]initWithData:dataReturned]; //newNSData

	
	NSString *requestPath = [[url URL] absoluteString];
	NSString *newString =[NSString stringWithUTF8String:[dataReturned bytes]];
	NSLog(@"the new string is %@",newString);
	
	self.theParser = [[ITMParser alloc] initParser];

	
	[xmlparser setDelegate:	self.theParser];
	
	BOOL worked = [xmlparser parse];
	if(worked)
	{
//..all the code that i pasted earlier
		
	}
	else
	{
		NSLog(@"IT did not work");
	}
}
Yes i want to use CD. Further down in the process of this application, i want to retrieve customer data from web service and store it in CD . Like a complete employee table with 5/6 fields. Customer table with 8/9 fields. So they could be 10000 records. So i will very much use CD in storing and fetching. This is a simple start up. Hope you get my point. Thanks.
No it won't, because this line is not a complete statement.
Code:
Employee *emp  = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee"
If you want to continue using CD, then I already gave you a good solution. Use NSUserDefaults to store the path to where they saved their data. Then on launch of the application use it to load the data if that path is still valid.

This is how applications like iTunes and iPhoto know where to save/load their libraries. But if there isn't a library there it will prompt you to save a new one or load an old one.

Edit: Also sending the users password in plain text and as a url parameter is horribly insecure.
jared_kipe is online now   1 Reply With Quote
Old Feb 10, 2013, 03:18 PM   #14
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
Code:
Employee *emp  = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:self.moc];
I dont know how the inManagedObjectContext got cut off here in my post..but in my code its like i wrote above.

Quote:
If you want to continue using CD, then I already gave you a good solution. Use NSUserDefaults to store the path to where they saved their data. Then on launch of the application use it to load the data if that path is still valid.
Can you give me an example. I used NSUserDefaults to store empid,asmx paths and stuff like that in settings bundle and a plist. But the actual core data was in sqlite DB. So its a little confusing.
RookieAppler is offline   0 Reply With Quote
Old Feb 10, 2013, 04:04 PM   #15
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Quote:
Originally Posted by RookieAppler View Post
Code:
Employee *emp  = (Employee *)[NSEntityDescription insertNewObjectForEntityForName:@"Employee" inManagedObjectContext:self.moc];
I dont know how the inManagedObjectContext got cut off here in my post..but in my code its like i wrote above.



Can you give me an example. I used NSUserDefaults to store empid,asmx paths and stuff like that in settings bundle and a plist. But the actual core data was in sqlite DB. So its a little confusing.
Giving you a full working example would be basically doing the whole thing for you.

Start small, hard code in the path to the file you already saved and get your application to load it automatically.

Then get your app to save the path to a key in your NSUserDefaults for the currently open data file when your application quits (or periodically).

Put both of them together and you can just automatically load your last used database.
jared_kipe is online now   0 Reply With Quote
Old Feb 10, 2013, 04:45 PM   #16
ElectricSheep
macrumors 6502
 
Join Date: Feb 2004
Location: Wilmington, DE
Send a message via AIM to ElectricSheep
You should take a look at the StickiesWithCoreData sample project in XCode's Organizer. It contains sample code that demonstrates how to save your managed object context to a pre-determined locations.
__________________
15'' MBP (early 2011) | i7 3770k Hackintosh | i7 Mac Mini (late 2012) | iPhone 5 | iPad 3 (2012) | iPad mini | MacOS X 10.9.2
ElectricSheep is offline   0 Reply With Quote
Old Feb 11, 2013, 11:02 AM   #17
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@ElectricSheep. I couldnt find the example in my Developer tools. I looked up google also, but could not find the example.
RookieAppler is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Tags
cocoa, ios, mac, save, work

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Cocoa Application: Setting Custom Background Image ajbudis Mac Programming 1 Jul 22, 2013 11:42 AM
General: Opening the executable in an IPA StevenMeyer Jailbreaks and iOS Hacks 1 Oct 9, 2012 11:40 AM
Need Assitance in creating a simple Cocoa OS X application lilabila Mac Programming 2 Aug 18, 2012 12:52 PM
How to show/hide objects in Cocoa Applescript application sjmonty99 Mac Programming 3 Aug 6, 2012 11:02 AM
How to pass commandline argument in cocoa application? Ram Thakkar Mac Programming 1 Jul 7, 2012 06:57 AM

Forum Jump

All times are GMT -5. The time now is 10:53 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC