updated the code using Xcode 6.1