Add /subtract minutes to or from NSDate [closed] - ios

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I need to subtract 15 minutes from a date. Note understanding why following is not working:
eventDate = event.date;
NSDate *alarmDate = [[eventDate] dateByAddingTimeInterval:-60*15];//this is throwing error "Expected identifier"
Thanks for any suggestions.

You've got a syntax error in your code, square braces must only be used when you are sending a "message" to an object. Do not use Objective-C square brace syntax in any other situation.
Here is the correct code:
eventDate = event.date;
NSDate *alarmDate = [eventDate dateByAddingTimeInterval:-60*15];

Related

NSString contents changes from orginal text during object creation [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
This is the best reduced case of I am seeing
NSString * test = #"??( ";
NSLog(#"'%#'", test);
console> '['
I have a work around
NSString * test = #"\x3f\x3f(";
NSLog(#"'%#",test);
console> '??('
It seems like this is likely caused by string interpolation or similar process in the NSString object vivification. I'm posting this question for two reasons.
1) anyone happen to know what is actually causing this?
2) I didn't find anything on this 'feature' of NSString and it took me an hour to track down the bug, so this is just a bread crumb for future programmers. Using the hex code for the character was the work around.
NSlog("'%#'", test); is syntactically incorrect. How are you compiling it with this syntax error?
If I change it to NSLog(#"'%#'", test);, it works correctly (note the string literal denoting # and the uppercase L in NSLog).

Time() shows "" rather than the current time string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Uses DateUtils;
.....
var d:TDateTime;
begin
d:=Time();
ShowMessage(DateTostr(d));
end;
it shows "" rather than the current time string
Your comment welcome
You get odd results because Time returns a the date 1899-12-30 with the current time, and DateToStr returns the date as a string.
I question your claim that it shows an empty string though as it shows the following on my end:
So you either need to return the full date and time like this:
d := Now;
but note that if you show the date, you're still not showing the time, so instead you need to show the time portion of the TDateTime variable instead of the date portion:
ShowMessage(TimeToStr(d));

Change label to integer using string with format [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want that every time a user clicks a button the number inside of it increases by 1. Below is the code to do that which works fine. However i want it to be in brackets e.g (1) when they press the button changes to (2) etc. How do i do this?
Thanks
-(IBAction)passButton:(id)sender{
passCounter = passCounter + 1;
passLabel.text = [NSString stringWithFormat:#"%i",passCounter];
}
-(IBAction)passButton:(id)sender{
passCounter++;
passLabel.text = [NSString stringWithFormat:#"(%i)",passCounter];
}
passLabel.text = [NSString stringWithFormat:#"(%i)",passCounter];

ruby, regex extract price from string [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
In ruby i have a string like this:
str= 43,69 €
Is possible with a regex obtain 43,69 ?
I have tried with:
/\d+(?:\.\d+)?/
but the output is incorrect: 43.0
This should work
/\d+(?:[.,]\d+)?/
The [.,] part matches decimal separator for a dot or a comma. If you are sure thet decimal separator will be a comma, you can use this:
/\d+(?:,\d+)?/

Save NSDate in core data XCode 5.0 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I want to save NSDate in core data model.
for example I want to store value for 'birthDate' in model 'User'.
Any help?
Select the attribute and change its type to date
As #inder and Martin Create an attribute of type "Date" in the model inspector
and store it using,
NSDateFormatter *dt = [[NSDateFormatter alloc] init];
[dt setDateFormat:#"yyyy-MM-dd"]; // for example
NSDate *bdate = [dt dateFromString:#"2012-10-15"];
[Sets setValue:bdate forKey:#"birthDate"];

Resources