Adapted code to XCode6-Beta6