Use of Blocks(Closures) or Completion Handlers with Function in Swift – iOS

Blocks in Objective-C

In Objective-C we are using the blocks(completion handlers) with functions as follows :

[code language=”obj-c”]
– (void)yourFunctionName:(NSString *)yourString withCompletionHandler:(void (^)(NSString *yourResult))block;
[/code]

Closures in Swift

Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages.

Syntax with Function

[code language=”obj-c”]
func yourFunctionName(parameter:Type, … , withCompletionHandler:(result:Type) -> Void)
[/code]
For more closure syntax : goshdarnclosuresyntax.com

Example

Function Definition:
[code language=”obj-c”]
func closureReturn(isTest:Bool, withCompletionHandler:(result:String) -> Void) {
if(isTest){
withCompletionHandler(result: "Yes")
}
else{
withCompletionHandler(result: "No")
}
}
[/code]
Calling Function:
[code language=”obj-c”]
closureReturn(true) { (result) -> Void in
print(result)
}
[/code]
Output should be respective to value true/false.


In next post I will write a tutorial on a wrapper class for Alamofire with use of SwiftyJSON by using closures.

It will be related to this post How to use Alamofire and SwiftyJSON with Swift? – Swift 2 – iOS 9 – Xcode 7

Happy Coding 🙂

Parse – See You Again – News & Useful Migration Tool & Alternative Links

Parse
Parse

Parse is Mobile Backend as a Service (MBaaS)
They have written :

We have a difficult announcement to make. Beginning today we’re winding down the Parse service, and Parse will be fully retired after a year-long period ending on January 28, 2017. We’re proud that we’ve been able to help so many of you build great mobile apps, but we need to focus our resources elsewhere.

News

Migration Tools and Alternatives

Thank you Parse for your great service.
See you again 🙂
Anything should be happen you have to learn something new anytime 😉
Enjoy iOS enjoy life 🙂

Issue "This certificate has an invalid issuer" because of Apple Worldwide Developer Relations Intermediate Certificate Expiration

I am posting this article because many users are facing this issue like “This certificate has an invalid issuer”

This certificate has an invalid issuer
This certificate has an invalid issuer

As apple have written :

The Apple Worldwide Developer Relations Certification Intermediate Certificate expires soon and we’ve issued a renewed certificate that must be included when signing all new Apple Wallet Passes, push packages for Safari Push Notifications, and Safari Extensions starting February 14, 2016.

As I found an answer in post on the Stack Overflow : This certificate has an invalid issuer regrading Intermediate Certificate Expiration

Follow this steps :

  1. Open KeyChain access, Delete “Apple world wide Developer relations certification authority” (Which expires on 14th Feb 2016) from both “Login” and “System” sections. If you can’t find it, use “Show Expired Certificates” in the View menu
  2. Download AppleWWDRCA.cer and add it to Keychain access > certificates (which expires on 8th Feb 2023)
  3. Everything should be back to normal and working now (Check the certificate is valid and it should be display in green)

Related Articles: