Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
Here is what I have so far. The only thing this needs to do is detect the date, and then depending on what that date is, post something different to Facebook. I only have it set up with one If statement for the moment just for testing. When I run it, it doesn't post the else statement, since today isn't Sunday.
Code:
-(IBAction)evite {
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:@"MM-dd-yyyy HH:mm"];
	todaysDate = [formatter stringFromDate:[NSDate date]];
	NSString *day = [todaysDate substringWithRange:NSMakeRange (3, 2)];
	if (day = "Sunday") {
		NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
		SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Sunday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
		SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];
	}
	else
	{NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
	SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Wednesday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
	SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];}
	
	
	
	
}
 
Thanks, if I read correctly, EEEE is what shows the full day name. I changed the formatter to this, and added the @"Sunday" to the code and have this.
Code:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:@"EEEE"];
	todaysDate = [formatter stringFromDate:[NSDate date]];
	
	if (todaysDate = @"Sunday") {
		NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
		SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Sunday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
		SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];
	}
	else
	{NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
	SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Wednesday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
	SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];}
The warnings disappeared, but it still doesn't give the desired effect. Am I at least heading in the correct way?
 
Code:
-(IBAction)evite {
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:@"MM-dd-yyyy HH:mm"];
	todaysDate = [formatter stringFromDate:[NSDate date]];
	NSString *day = [todaysDate substringWithRange:NSMakeRange (3, 2)];
	if ([COLOR="Red"]day = "Sunday"[/COLOR]) {
		NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
		SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Sunday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
		SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];
	}
	else
	[COLOR="Red"]{[/COLOR]NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
	SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Wednesday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
	SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[actionSheet showInView:self.tabBarController.view];[COLOR="red"]}[/COLOR]
	
	
}
The first red-hilited expression is wrong in several ways:
1. It's using assignment (=) instead of equality-test (==).
2. It's "comparing" to a C string ("foo"), not an NSString (@"foo").
3. Don't use == for comparing NSString equality, use the -isEqualToString: method of NSString.

The red-hilited { } are hard to see. Even when hilited in red. Use whitespace to make them more obvious.


For the overall design, you should probably use a switch statement, and use case labels that are the numeric values for days of the week. See NSDateComponents.
http://developer.apple.com/library/...ptual/DatesAndTimes/Articles/dtCalendars.html
 
Got it figured out thanks to help from another developer. Code used was Gregorian calendar from NSCalendarComponent:
Code:
-(IBAction)evite {
	NSCalendar* gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease];
	NSDateComponents* theDateComponents = [gregorian components: NSWeekdayCalendarUnit fromDate: [NSDate date]];
	NSInteger weekDay = theDateComponents.weekday;
	NSLog(@"Today is day %ld", weekDay);	
	if (weekDay == 1, 5, 6, 7) {
		NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
		SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Sunday!  Bible Class @8:45 Worship @10:00!  Click link for our website."];
		SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
		[item setCustomValue:@"https://fbcdn-photos-a.akamaihd.net/photos-ak-snc1/v43/136/198020576909620/app_1_198020576909620_358.gif" forKey:@"picture"];
		[actionSheet showInView:self.tabBarController.view];
	}
	else
	{NSURL *url = [NSURL URLWithString:@"http://www.marsalisavenuecoc.org"];
	SHKItem *item = [SHKItem URL:url title:@"Join me @ Marsalis Avenue Church of Christ this Wednesday!  Bible Class @10AM Study @7:00!  Click link for our website."];
	SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
	[item setCustomValue:@"https://fbcdn-photos-a.akamaihd.net/photos-ak-snc1/v43/136/198020576909620/app_1_198020576909620_358.gif" forKey:@"picture"];
	[actionSheet showInView:self.tabBarController.view];}
	
	
	
	
}
 
Code:
	if (weekDay == 1, 5, 6, 7)

If that conditional is supposed to mean "if weekday is equal to one of the values 1, 5, 6, or 7", then that's not what it does.

It's syntactically valid C code, which means it will compile without an error or warning. It just doesn't do what I think you intend it to do.
 
If that conditional is supposed to mean "if weekday is equal to one of the values 1, 5, 6, or 7", then that's not what it does.

It's syntactically valid C code, which means it will compile without an error or warning. It just doesn't do what I think you intend it to do.

What is it doing? I run it in the simulator, and it works the way I intend. If it is Sunday Thursday Friday or Saturday it runs the code, but if it is a different day it runs the else code. However, in the actual iOS used for testing...it only uses the if statement, and never the else.
 
What is it doing? I run it in the simulator, and it works the way I intend. If it is Sunday Thursday Friday or Saturday it runs the code, but if it is a different day it runs the else code. However, in the actual iOS used for testing...it only uses the if statement, and never the else.

http://en.wikipedia.org/wiki/Comma_operator

You could use switch and case, as already mentioned.

You could also make an NSIndexSet containing 1, 5, 6, 7, then use containsIndex:weekday in the conditional.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.