- (AFSecurityPolicy*)securityPolicyCert
    NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"" ofType:@"cer"];
    NSData *certData = [NSData dataWithContentsOfFile:cerPath];
    AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
    securityPolicy.allowInvalidCertificates = NO;
    securityPolicy.pinnedCertificates = @[certData];
    securityPolicy.SSLPinningMode = AFSSLPinningModePublicKey;
    return securityPolicy;

AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];

op.responseSerializer = [AFJSONResponseSerializer serializer];

// SSL Pinning

[op setSecurityPolicy:[self securityPolicyCert]];

[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {


} failure:^(AFHTTPRequestOperation *operation, NSError *error) {




[op start];

Language: ObjectiveC

a) Added SFHFKeychainUtils to the project

b) Generated CFUUID key String

 CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
    udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));

c) Saved it to Key Chain Utils

+ (NSString *)GetDeviceID {
    NSString *udidString;
   udidString = [self objectForKey:@"deviceID"];
    CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
    udidString = (NSString*)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, cfuuid));
        [self setObject:udidString forKey:@"deviceID"];
    return udidString;

+(void) setObject:(NSString*) object forKey:(NSString*) key
    NSString *objectString = object;
    NSError *error = nil;
    [SFHFKeychainUtils storeUsername:key

        NSLog(@"%@", [error localizedDescription]);

+(NSString*) objectForKey:(NSString*) key
    NSError *error = nil;
    NSString *object = [SFHFKeychainUtils getPasswordForUsername:key
        NSLog(@"%@", [error localizedDescription]);

    return object;

from StackOverflow

Language: Objective C

UIView frame animation

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:duration];
//old position
    customView.frame = CGRectMake(10, customView.frame.origin.y, 300, 80);
    [UIView animateWithDuration:duration
//new position
                         customView.frame = CGRectMake(10, customView.frame.origin.y+offset, 300, 80);
                     completion:^(BOOL finished){
    [UIView commitAnimations];

check if an email is valid in Objective c

- (BOOL)mailIsValid:(NSString*)mail {
    NSString *emailRegEx =
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    return [emailTest evaluateWithObject:[mail lowercaseString]];

A simple beacon manager to integrate this new technology in yours iOS project.

Installation is very simple:

– copy iBeaconManager.h and iBeaconManager.m in your project.

– write [iBeaconManager sharedInstance] in didFinishLaunchingWithOptions

– set a correct UDID for your beacon device

– this manager send a notification “BeaconsFounded” to all yours ViewController.


Download files

if  you having a trouble you can contact me.

i share a video to you that inspired me


Dynamic TableViewCell Height with Autolayout 

Difficulty: Easy

XCode 5.1 – iOS 7 – Objective C

5 Steps

  1. Step: New Project
  • Select File->New Project and choose Single View Application

Schermata 2014-09-07 alle 16.12.28

  • Insert project name “automaticTableViewCell”

Schermata 2014-09-07 alle 16.15.01


2. Step: Storyboard

  • Drag a TableView in the ViewController  created automatically by Xcode

Schermata 2014-09-07 alle 16.26.31

  • Add Constraints

Schermata 2014-09-07 alle 16.26.09


3. Step: Create Custom Comment Cell

  • File->New File and choose Objective c class

Insert in Class “CommentTableViewCell” Subclass of “UITableViewCell” and check “Also create a Nib file” { image }

Drag a UIImageView and a UILabel in the xib file

Add Constrains for UIImage Pin and Width and Height { image }

Add Constrains for UILabel only Pin { image }

This is a Summary of Constrains  { image }

I modified Vertical Space Relation of UIImageView from “Equal” to “Greater than or Equal” { image }

4 Step: .h file

Add IBOutlet for Table View from Storyboard:

1- click on storyboard and select UITableview in the ViewController

2- Click on “Show the Assistant Editor”

Schermata 2014-09-07 alle 16.26.46

3- Press ctrl on table View and drag in the .h file

Schermata 2014-09-07 alle 16.27.12

Add in the .h file an array for the items of the Table and a stub Cell

you need to import CommentTableViewCell.h.

This is .h file:

#import <UIKit/UIKit.h>

#import “CommentTableViewCell.h”

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *aTableView;

@property (nonatomic, strong) NSArray *comments;

@property (nonatomic, strong) CommentTableViewCell *prototypeCell;



5. Step: .m file

- (void)viewDidLoad

- (void)viewDidLoad


    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.aTableView.delegate = self;

    self.aTableView.dataSource = self;

    UINib *cellNib = [UINib nibWithNibName:@”CommentTableViewCell” bundle:[NSBundle mainBundle]];

[self.aTableView registerNib:cellNib forCellReuseIdentifier:@”Cell”];

self.comments = [[NSMutableArray alloc] init];

    _prototypeCell = [cellNib instantiateWithOwner:nil options:nil][0];

    for (int i = 0; i<10; i++) {

        [self.comments addObject:@”very long text”];



– tableview method

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath


    [self configureCell:_prototypeCell forIndexPath:indexPath];

    [_prototypeCell layoutSubviews];

    CGFloat height = [_prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

    return height + 1;


- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath


    return 44.f;


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.items.count;


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @”Cell”;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    [self configureCell:cell forIndexPath:indexPath];

    return cell;


- (void)configureCell:(UITableViewCell*)cell forIndexPath:(NSIndexPath*)indexPath {


   CommentTableViewCell *tCell = (CommentTableViewCell *)cell;

    tCell.iconImg.backgroundColor = [UIColor redColor];

    tCell.titleLbl.text = [self.comments objectAtIndex:indexPath.row];