Skip to content

Instantly share code, notes, and snippets.

View jaisonv's full-sized avatar

Jaison Vieira jaisonv

View GitHub Profile
@jaisonv
jaisonv / Note.txt
Created November 25, 2017 02:17
Error running tests on framework when your framework has third party frameworks dependencies
When adding a third framework to yours you may face the following error if you try to run tests:
The bundle “[framework-name]Tests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
(dlopen_preflight([framework-path]): Library not loaded: @rpath/[third-framework-name].framework/[third-framework-name]
Referenced from: [derived-data-framework-path]
Reason: image not found)
Program ended with exit code: 82
This problem can be solved by adding "$(PROJECT_DIR)" to the "Runpath Search Paths" on the framework's Build Settings.
@jaisonv
jaisonv / TableViewController.m
Created December 8, 2016 02:01
Reload tableview when scrolling
pageNumber = 1;
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
NSInteger currentOffset = scrollView.contentOffset.y;
NSInteger maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
if (maximumOffset - currentOffset <= - 40 && hasNextPage)
{
[self fetchData];
@jaisonv
jaisonv / SortArray.m
Last active July 25, 2016 20:45
Sort array
// 'date' is the property with the date to be sorted by
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
// 'myArray' is the array that will be sorted
NSArray *sortedEventArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
@jaisonv
jaisonv / TableViewController.m
Created June 15, 2016 06:52
Remove empty cells that appear before loading
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
@jaisonv
jaisonv / TableViewController.m
Created June 15, 2016 06:43
Reload single row in a UITableView
// selectedRow is the row to update
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:selectedRow inSection:0];
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
[tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
@jaisonv
jaisonv / TableViewController.m
Created June 15, 2016 03:59
Expand / colapse UITableViewCell
NSInteger selectedRow = -1; // default selected row (here no one)
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == selectedRow) {
return 100; // expanded height
}
return 44; // colapsed height
}
@jaisonv
jaisonv / ImageScaled.m
Last active April 13, 2016 03:13
Scale image based in a width
-(UIImage *)scaleImage:(UIImage *)image toWidth:(int)width {
// determine the scaling factor to fit the screen width
CGFloat oldWidth = image.size.width;
NSUInteger newWidth = (width - 10);
CGFloat scaleFactor;
if (oldWidth > newWidth)
scaleFactor = oldWidth / newWidth;
else
@jaisonv
jaisonv / Info.plist
Created January 19, 2016 01:23
Make status bar font white
View controller-based status bar appearance = NO
Status bar style = UIStatusBarStyleLightContent
@jaisonv
jaisonv / RegexExample.swift
Created October 2, 2015 02:35
Working with regex in Swift
let text = "Text to get the match"
let regex = NSRegularExpression(pattern: "([^ ]+)", options: nil, error: nil)!
let matches = regex.matchesInString(text, options: nil, range: NSRange(location: 0, length: count(text)))
var substring = ""
for match in matches as! [NSTextCheckingResult] {
// range at index 0 returns the full match
// range at index 1 returns the first capture group
// range at index 2 returns the second capture group and so on...
@jaisonv
jaisonv / ViewController.swift
Created July 5, 2015 22:12
Go back to the last view controller
navigationController?.popViewControllerAnimated(true)