Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Error Handling in Swift 2

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 406
    Comment on it

    SWIFT

    Swift is a very powerful and simple programming language which is used for creating the iOS applications.Swift is a language which is designed to work with Apple's Cococa and Objective-C. The advantage of this language is that it is one the most secured and safest language for creating the applications that run lightening fast. The important feature of Swift that makes it different from other programming language is that it allows us to use the API's of Objective C in Swift and vice-versa.

    ERROR HANDLING IN SWIFT 2

    Error handling is a process which helps you to find the errors in the program and fix it for the smooth functioning of the program.Swift is a language which provides error handling using the try, catch and throw statements. Initially in Objective C error handling was something which wasn't taken care of. But in Swift error handling is more organised and easy.

       NSError *error = nil;
    
        // Execute Fetch Request
        NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    
        if (error) {
            // Handling the Errors
            ...
    
        } else {
            // Processing the Results
            ...
        }
    

    The above example is a demonstration how error handling was done in the Objective -C. Now with the enhanced version of Swift the error handling has become easy to implement.The Example below will help us understanding the same.

    do {
        // Execute Fetch Request
        let results = try managedObjectContext.executeFetchRequest(fetchRequest)
    
        // Processing the Results
        ...
    
    } catch {
        let fetchError = error as NSError
    
        // Handling the Errors
        ...
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: