Skip to content

Instantly share code, notes, and snippets.

View NikolaKirev's full-sized avatar
🎯
Focusing

Nikola Kirev NikolaKirev

🎯
Focusing
View GitHub Profile
@NikolaKirev
NikolaKirev / HashtagFiltering.m
Last active December 28, 2015 21:09
Find hashtag words in an NSString using NSPredicate
//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);
@NikolaKirev
NikolaKirev / ios5direcyions.m
Created April 28, 2013 04:53
iOS5 Map Directions
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]];
@NikolaKirev
NikolaKirev / activity.m
Created April 28, 2013 04:45
iOS Activity VC
- (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];
}
}
@NikolaKirev
NikolaKirev / weekday.m
Created April 12, 2013 04:23
Using Localised Weekday Name Strings
- (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];
@NikolaKirev
NikolaKirev / mapDirections.m
Last active December 16, 2015 02:29
Map Directions tutorial
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];
@NikolaKirev
NikolaKirev / android_action_bar.java
Created April 6, 2013 17:15
Android Tutorial:Adding buttons in the action bar part 2
@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) {
@NikolaKirev
NikolaKirev / android_action_bar.xml
Created April 6, 2013 17:14
Android Tutorial: Adding buttons in the action bar part1
<?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"
@NikolaKirev
NikolaKirev / FizzBuzz.m
Last active December 15, 2015 19:08
Objective-C: FizzBuzz
- (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");
@NikolaKirev
NikolaKirev / gist:5236003
Created March 25, 2013 09:38
Simple UIView ANimation with blocks - iOS
[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
}];
@NikolaKirev
NikolaKirev / NSPredicateFiltering
Created February 13, 2013 05:52
Filtering an array with NSPredicate
NSString *companyName =@”Apple”;
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"company == %@", companyName];
NSArray *filteredArray =[originalArray filteredArrayUsingPredicate: predicate];