Thiago - Tech Director, Principal Architect and software developer for many different languages. I am passionate about the development of any kind. I am a developer since 1996, coding for many different styles such as Cold Fusion, Java, PHP, PL-SQL, Objective-C, Nodejs and many others..anything needed we can translate to code.
Tuesday, March 15, 2016
IOS Exceptions - Objective C
Hello everyone,
As part of the teaching process on IOS-Development, today I am going to show you guys a little bit more about exceptions in Objective-C.
I would say that in Objective-C you don’t see that much as you can see in Java Exceptions. But I do like and I add in my code as much as needed .Try/catch/finally blocks can be useful to capture errors that may otherwise cause an app to fail. So, yes, please use them.
In this simple example below I am allocating an array, but I am not adding any elements on it. Inside the try block the attempt to access the first element will cause an exception to be thrown. So, that’s the easiest way to see something happening, right? Let’s go!
The output of the code is shown below:
iPhoneApp[4769:b601] NSException caught
iPhoneApp[4769:b601] Exception Name: NSRangeException
iPhoneApp[4769:b601] Exception Reason: *** -[NSArray objectAtIndex:]: index 0 beyond bounds for empty array
iPhoneApp[4823:b601] In finally block
The @finally clause as in java is called, it's called anyway. So, this is perfect place to add some methods such as code cleanup, connections released and so on.
Using exceptions can be very helpful when working with files (eg: exampleNSFileHandleOperationException), when working with data from unknown sources it helps a lot.
Catching or Throwing specific exceptions by the usage of method call, check it out:
I hope you liked and talk to you soon!
I hope it helps and happy coding,
Thiago Leoncio
------------------------------------------------------
Other great IOS articles:
IOS - 3 big reasons why start coding in swift instead of Objective-C
IOS - IOS App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.
IOS - Video using 3D framework
IOS - Video Application with Json and Mysql connection
IOS - How to create Multiple views
Saturday, February 13, 2016
Apache Cordova - How to install Apache Cordova and run a project on Mac with Visual Studio IDE
Hello everyone,
Today I am gonna a show you how to make it possible develop and debug Apache Cordova and Ionic projects using Visual Studio IDE on Mac.
First download Visual Studio Code at Microsoft page from your MAC:
https://code.visualstudio.com/Download
Then if you don't have HomeBrew installed, please do it.
Homebrew is a package manager for the Mac and it makes installing most open source sofware (like Node.JS) as simple as writing brew install node.
To install Homebrew just open Terminal and type ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
Please find more about Apache Cordova here:
Apache Cordova Debugging Tools
Apache Cordova run Android app
Today I am gonna a show you how to make it possible develop and debug Apache Cordova and Ionic projects using Visual Studio IDE on Mac.
First download Visual Studio Code at Microsoft page from your MAC:
https://code.visualstudio.com/Download
Then if you don't have HomeBrew installed, please do it.
Homebrew is a package manager for the Mac and it makes installing most open source sofware (like Node.JS) as simple as writing brew install node.
To install Homebrew just open Terminal and type ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
Now the Cordova piece of if:
Open a Terminal (on a Mac) and if you're planning on targeting iOS devices,
Install HomeBrew on your Mac.
Open a Terminal and run brew install ideviceinstaller ios-webkit-debug-proxy
Cordova debug environment
Go to your Visual Studio installed and open a cordova project code that you have or just download a sample on Github.
Type Command + P to open a terminal box in your Visual Studio and type ext install cordova
then
Now you need to enable the debug environment as well as your emulators. So click on debug button from your Visual Studio code IDE
.
Configure gear icon () to choose the Cordova debug environment.
Now you are good to go! Just select the emulator, device or browser that you want to launch it, hit play and go fot it!
Please find more about Apache Cordova here:
Apache Cordova Debugging Tools
Apache Cordova run Android app
I hope it helps you and happy codding,
Thiago Leoncio.
Subscribe to:
Posts (Atom)









