|
Declare and set a variable called myName to your name
Declare two more string variables introduction and japaneseIntroduction both with an NSString type
Set introduction using stringWithFormat class method "My name is %@", myName
Set japanese introduction using stringByAppendingString instance method by appending " to moushimasu"
Print introduction and japanese introduction
Step 3: Define and call a new function
Declare a function called printIntroductions
The function should accept an NSString as a parameter called name
Cut and paste the introduction and japaneseIntroduction code inside of the new function
You should have errors for referencing 'myName'. Change any reference to 'myName' to 'name'.
This is an error of scope. You only declared 'myName' in your didFinishLaunching method. Not in your new method. In your new method, you declared an argument called 'name' that your function accepts when the method is called
In your didFinishLaunching method after you set myName call printIntroductions: and pass in 'myName' as an argument
It should print out the introduction and Japanese introduction
Step 4: Recurse through a function
Add a new function called countDownTillIntroduction: that accepts an integer called numberOfDays as an argument
The function should do the following:
Check to see if the numberOfDays is 0
If the number of days is 0, it should print "The time has come"
If numberOfDays is not 0
It should print "[numberOfDays] days left until introductions"
It should declare and set a variable oneLessDay and set it to numberOfDays - 1
It should then call countDownTillIntroduction and pass in oneLessDay
In the didFinishLaunching method before you call printIntroductions call countDownTillIntroduction and pass in 4
Completion:
OUTPUT: You should see it print "4 days left until introductions", "3 days left until introductions" (down to 1) and then it should print "The time has come" and "My name is [yourName]", "[yourName] to moushimasu"
|
|
|
|
|
What is your expectation here? Do you want someone to write that program for you? That will not happen. You should try it yourself and if you then run into a specific problem, come back, ask a specific question and probably someone can help you with that.
|
|
|
|
|
Ok so be honest here.
This is codeproject.com not homeworkcheat.com. If you are having some problems and need help with a question about then ask but include the work you have completed and where you are stuck.
everyone here is and has taken the effort to learn what is they do. you should be expected to the same if you ever expect to be successful.
Learning is a part of life.
|
|
|
|
|
I think almost everybody reading a discussion board on Objective-C would be able to "solve this project".
Do you have any other questions?
|
|
|
|
|
Is it possible to design an iPad app that launches Safari, waits until a dialog box appears in Safari and then activates a button. Waits until another dialog box appears and then automatically completes the username and password in Safari and finally the app closes itself?
I cannot use Autofill as the website that Safari has accessed does not allow saving passwords. An analogy would be Safari automatically connecting to one's banks website that does not allow saving username and passwords.
This is an app I am trying to develop for visually impaired people for easy login access to the local library.
All constructive comments are welcome.
modified 8-Jan-15 18:01pm.
|
|
|
|
|
To the best of my knowledge the short answer is no.
If it were possible then I highly doubt that you would be able to get this released into the Store because of the privacy concerns that something like this could create.
If this is your app and web site then there are other alternatives available for you to try. From your app you could launch a website and pass in parameters via the url. Then on your website have some javascript that runs and takes care of what remains.
Though of course you will have the issue of passing passwords as free text via the url. Definitely requires some more more thought but alas that is for another thread.
|
|
|
|
|
to my knowledge this is not possible.
I saw some password tools (like 1Password, LastPass) on the appstore that opens up a website on an internal browser and then fill in the username and password.
But to my knowledge apple doesen't allow IPC between most of the Apps. The only place where Apps are communicating is AppleHealth where 3th party apps could write to AppleHealth.
If you find a way to opening up safari and then fill in the user and password boxes i'm extremly interested in the solution!
|
|
|
|
|
I'm trying to make a pretty simple frontend program that's able to start up a java program when it's run, but haven't yet mastered OC. Someone suggested that I try using a console command (code below), but I haven't been able to make that work yet.
Is there an easier way to do this, or does any one here know where my code has gone wrong?
int main(int argc, const char * argv[]) {
NSFileManager *filemgr;
NSString *currentpath;
filemgr = [[NSFileManager alloc] init];
currentpath = [filemgr currentDirectoryPath];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *file = pipe.fileHandleForReading;
NSTask *task = [[NSTask alloc] init];
task.launchPath = [currentpath stringByAppendingString:@"/java"];
task.arguments = @[@"-jar", @"PolyGlot.jar"], [NSString stringWithFormat:@"%c", argv]];
task.standardOutput = pipe;
[task launch];
NSData *data = [file readDataToEndOfFile];
[file closeFile];
NSString *grepOutput = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"grep returned:\n%@", grepOutput);
return 0;
}
When I run this, I get the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'
I know that the current path is accessible, though... so I'm kind of stumped here. Any help would be much appreciated. Thanks!
|
|
|
|
|
As a guess because what you think is the current path for the executable is not in fact the path where the jar actually is.
|
|
|
|
|
Part of the trouble I'm having here is that I'm ultimately trying to reproduce the Terminal line:
java -jar PolyGlot.jar <FILENAME_ARGUMENT >
Do you have any ideas for that? Any help would be appreciated.
|
|
|
|
|
task.launchPath = [currentpath stringByAppendingString:@"/java"];
Are you sure that the java executable is in that path? Printing out the full path at that point will tell you.
|
|
|
|
|
Ah, I do see what I was doing there! I was fundamentally misunderstanding how java was being referenced. I almost have it working at this point! Here's the code as it stands now:
int main(int argc, const char * argv[]) {
NSFileManager *filemgr;
NSString *currentpath;
filemgr = [[NSFileManager alloc] init];
currentpath = [filemgr currentDirectoryPath];
NSPipe *pipe = [NSPipe pipe];
NSFileHandle *file = pipe.fileHandleForReading;
NSTask *task = [[NSTask alloc] init];
task.launchPath = @"/usr/bin/java";
task.arguments = @[@"-jar", [currentpath stringByAppendingString:@"/PolyGlot.jar"], [NSString stringWithFormat:@"%c", argv]];
task.standardOutput = pipe;
[task launch];
NSData *data = [file readDataToEndOfFile];
[file closeFile];
NSString *grepOutput = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"grep returned:\n%@", grepOutput);
return 0;
}
The only remaining problem is that the "-jar" argument seems to be ignored at this point. If I apply it by itself, Java recognizes it as an argument, but otherwise, it is only accepting "PolyGlot.jar". Is there something that I'm not doing correctly there?
Thanks for the help so far!
|
|
|
|
|
I don't know Objective-C, but I suspect that the first argument should be the same as task.launchPath , i.e the program name. That would then comply with the format of the argv array, as set by the shell when invoking programs from the command line.
|
|
|
|
|
The task.launchPath is the full path of the program to be run. Out of curiosity, I tried dropping " -jar" onto the end, but that made it fail when it looked for the executable "java -jar" rather than the executable "java" with the argument "-jar".
What's strange is that the "-jar" argument works correctly so long as it's the only one... Ultimately, the error I'm getting from Java at this point is "
Could not find or load main class ". This typically appears if you try to run a .jar file without the -jar argument.
Also, just for the sake of sanity, I'll specify that I can run "java -jar PolyGlot <FILENAME>" from the console, and it runs fine.
|
|
|
|
|
DraqueD wrote: I can run "java -jar PolyGlot <FILENAME>" from the console, and it runs fine. And I think those are the fields that you need in your arguments array. The last parameter you specify should be argv[1] as a string (%s), not a character (%c), as that is the filename passed in to your program. Something like:
task.launchPath = @"/usr/bin/java";
task.arguments = @[task.launchPath, @"-jar", [currentpath stringByAppendingString:@"/PolyGlot.jar"], [NSString stringWithFormat:@"%s", argv[1]]];
|
|
|
|
|
As a heads up, I found my solution! It turns out that the debug folder that this was running in gave Java particular troubles, and the behavior cleared up when I took my compiled app into a typical folder. Thanks to everyone who replied for the help!
|
|
|
|
|
I think there is an problem in executable path..Check out that
|
|
|
|
|
We've just completed an iOS app called Waffle which is launching in the new year and are looking for Node.js developers to join our team.
Waffle is a a community for you to share your thoughts & learn from the world around you. Jump into group chats with people who share your interests and enjoy fast, flowing conversations on the things you’re passionate about.
We have a 3 strong team with backgrounds working for Microsoft. EASA and are looking for hard working and passionate developers either part or full time.
If you're interested please email sharan@waffleapp.co
Sharan
|
|
|
|
|
In objective-c I’m try to create a statement that toggles a variable that switches between two numbers with a UIswitch controller
(a * b/w * r) c * h;
r needs to trigger two different numbers
when on needs to = .73
when off needs to = .66
int a=1;
int b=5.14;
int c = -.015;
int w =1;
int r =.73;// on=.73 and off= .66
int h=1;
int result;
result = (a * b/w * r) c * h;
NSLog (@"a*b/w*r)c*h;");
Is this possible
|
|
|
|
|
Member 11251240 wrote: Is this possible Most likely but your question is far from clear. In general terms you would write something like:
if (switch == ON)
r = .73;
else
r = .66;
But maybe I just don't understand what you are asking.
|
|
|
|
|
What is the core difference between C programming language and Objective-C programming language? Please help me to know with suitable examples. A lot of Thanks in Advance.
Regards
Online Visit
online visit
|
|
|
|
|
C and Objective-C have many differences.
First of all, C is procedure-oriented language while object-C is object-oriented language.
They have different syntaxes.
Objective-C is more familiar to smalltalk than C/C++.
e.g. of calling method
c: foo(param1, para2, ...);
objective-c: [object foo:param];
There are many differences between two languages.
jian
|
|
|
|
|
thanks sir, but i need some real life example to clear this concept more.
Regards
Online Visit
|
|
|
|
|
Google will find you lots of documentation on both languages.
|
|
|
|
|