This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *companyName =@”Apple”; | |
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"company == %@", companyName]; | |
NSArray *filteredArray =[originalArray filteredArrayUsingPredicate: predicate]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[UIView animateWithDuration: 0.9 delay: 0 options: UIViewAnimationOptionCurveEaseInOut animations: ^(void)animations{ | |
CGPoint newCenter = CGPointMake(self.greenView.center.x + 180, self.greenView.center.y + 260); | |
[self.greenView setCenter: newCenter]; | |
}completion:^(BOOL finished){ | |
//this code is called after the aminations have completed | |
}]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)fizzBuzzToNumber:(NSInteger)endNumber { | |
for (NSInteger i=1; i <= endNumber; i++) { | |
if (i % 3 == 0) { | |
if (i % 5 == 0) { | |
NSLog(@"FizzBuzz"); | |
}else { | |
NSLog(@"Fizz"); | |
} | |
}else if (i % 5 == 0) { | |
NSLog(@"Buzz"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<menu xmlns:android="http://schemas.android.com/apk/res/android" > | |
<item | |
android:id="@+id/itemAdd" | |
android:icon="@drawable/add" | |
android:showAsAction="ifRoom|withText" | |
android:title="@string/btnAdd"> | |
</item> | |
<item | |
android:id="@+id/itemRefresh" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// TODO Auto-generated method stub | |
MenuInflater inflater = getMenuInflater(); | |
inflater.inflate(R.menu.menu, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class itemClass = [MKMapItem class]; | |
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { | |
MKMapItem *currentLocationItem = [MKMapItem mapItemForCurrentLocation]; | |
MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([natObject.latitude doubleValue], [natObject.longitude doubleValue]) addressDictionary:nil]; | |
MKMapItem *destinamtionLocItem = [[MKMapItem alloc] initWithPlacemark:place]; | |
destinamtionLocItem.name = [natObject name]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)localizedWeekdayStringForDate:(NSDate *)date { | |
// We first get the index of the weekday from NSDateComponents | |
NSCalendar *calendar = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:date]; | |
// The weekdays start from Sunday and from index 1 | |
// 1 - Sunday, 2 - Monday ... | |
int weekdayNumber = [components weekday]; | |
// We need an NSDateFormatter to have access to the localized weekday strings | |
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)sharePressed:(id)sender { | |
if (NSClassFromString(@"UIActivityViewController")) { | |
NSURL *urlStringToShare = _webView.request.URL; | |
NSArray *dataToShare = @[urlStringToShare]; | |
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:dataToShare | |
applicationActivities:nil]; | |
[self presentViewController:activityVC animated:YES completion:nil]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", | |
currentLocation.coordinate.latitude, | |
currentLocation.coordinate.longitude, | |
[destionationObject.latitude doubleValue], | |
[destionationObject.longitude doubleValue]]; | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A code snippet, that can be used to search for hashtags in a given NSString | |
//Instantiate a mutable array containing all the words. We sepparate the original string into words. | |
NSMutableArray *hashtagWordsArray = [NSMutableArray arrayWithArray:[<An NSString> componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]]; | |
NSPredicate *hashtagDetectionPredicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH %@", @"#"]; | |
[hashtagWordsArray filterUsingPredicate:hashtagDetectionPredicate]; | |
//Log the result | |
NSLog(@"Hashtags: %@", hashtagWordsArray); |