Showing posts with label objective-c. Show all posts
Showing posts with label objective-c. Show all posts

Monday, May 02, 2016

iOS Boot Camp

If your company is planning to go into iOS development, the 5-Day iOS Boot Camp is the most cost-effective way to get your developers jumpstarted. Available in Swift or Objective-C, this course focuses on all the important aspects of iOS development to jumpstart your developers in the shortest time.  We can conduct this course in house, or you can send your developers to our open classes.

Topics include:

  • Introduction to Objective-C or Swift
  • Storyboard
  • Location-Based Services
  • Design Patterns
  • Protocols and Delegates
  • Databases
  • Web Services
  • Background Fetch
  • Network Connectivity

We have conducted this course successfully worldwide. Contact Wei-Meng Lee @ weimenglee@learn2develop.net for details such as costing, venue, as well as in-house arrangements.

Learn iOS Programming using Swift

Learn how to program your iOS devices using Swift. In this course, you will learn the the fundamental building blocks of iOS programming:

  • Crash course in Swift
  • Using Storyboard
  • Views and View Controllers
  • Different types of applications
  • Location Based Services
  • Displaying Maps
  • File Storage
  • Background Fetch
  • SQLite Database

In addition, participants will also get 2 Swift cheat sheets updated to the latest version of Swift. These 2 cheat sheets are handy companions for every Swift developers! You can also download your own copy here:


 

Thursday, June 18, 2015

Learning iOS Programming?

So, you are planning to get started with iOS programming. Good for you. But how do you get started? I have the following two courses to get you started:

IOS101 - Fundamentals of iPhone Programming using Swift
IOS103 - Practical iOS Programming using the Swift Programming Language

Which course is suitable for you?

You should attend IOS101 if you:

  • Are new to iOS programming
  • Want to learn how to create iPhone apps using Swift

You should attend IOS103 if you:

  • Are already familiar with Objective-C and want to learn how to code in Swift
  • Want to learn advanced Swift features
  • Want to learn how to use Swift to create interesting iOS projects

Tuesday, December 02, 2014

Article - Using Objective-C and Swift together in iOS Apps

As an addendum to my previous article about the role of Swift in iOS app development, we now take a look at how Swift and Objective-C can be used together in iOS apps. Despite Apple’s intention to replace the Objective-C language using Swift, it is not practical in the short term simply due to the fact that developers are deeply entrenched in Objective-C. Rather than force Swift down the developer’s throat, Apple has made it easy to allow Objective-C to interoperate with Swift. In this article, I run through a couple of simple examples to illustrate first how you can use Swift within an Objective-C project, and then how to include Objective-C within a Swift project.

Read the article here.

Thursday, October 30, 2014

Why Swift Flies for iOS Developers

I recently wrote an article for MobiForge outlining the importance of Swift and the effect it has on the industry. I also took this opportunity to compare it with Objective-C. Here is the abstract of the article:

"Now that the dust has settled somewhat on Swift, the new language on the block for developing iOS and OSX applications, we take a look at its impact and improvements over its predecessor, Objective-C. Apple claims Swift to be a modern, safe, and powerful language for developing for iOS and OSX. Just how powerful is Swift compared to the venerable Objective-C? And how does it make developing applications easier and safer? In this article, I will walk you through some of the important features in Swift and how it improves on Objective-C. In a follow up article, I will show you how you can use Swift and Objective within the same project."
Check out the full article here

Monday, October 13, 2014

Swift - Dealing with pointers in Swift

When using certain APIs in Objective-C and C, you often have to deal with pointers. For example, you can write data to the NSOutStream object using the write:maxLength: method:

-(void) writeToServer:(const uint8_t *) buf {
    [oStream write:buf maxLength:strlen((char*)buf)];

}

The write:maxLength: method takes in a pointer of type unint8_t, containing the data you want to send across the stream. The equivalent of the above function in Swift is:

func writeToServer(dataToWrite:NSData) { 
    oStream!.write(
        UnsafePointer(dataToWrite.bytes)
        maxLength: dataToWrite.length) 
}

For reading of data, in Objective-C, you would supply an array of uint8_t:

uint8_t buf[1024]; 
unsigned int len = 0; 
len = [(NSInputStream *)stream read:buf maxLength:1024];

In Swift, you can use the following:

let buf = NSMutableData(capacity: 1024) 
var buffer = UnsafeMutablePointer(buf.bytes) 
let len = (aStream as NSInputStream).read(buffer, maxLength: 1024)

Tuesday, September 30, 2014

Swift - Calling Objective-C code

In Xcode 6, you now have the option to create a project using either Swift or Objective-C. In addition, you can also use Objective-C code in your Swift project. This post shows you how. 

1. First, create an iOS project that uses the Swift language

2. Add a Objective-C File file to your project. Name it as MyClass

3. You will be prompted with the following:


4. This will add a file named UsingObjC-Bridging-Header.h to your project. Behind the scene, Xcode automatically sets the Objective-C Bridging Header setting to this file:


5. Add a Header File file to your project. Name it as MyClass

6. Populate the MyClass.h with the following:

#import

@interface MyClass: NSObject

@property (strong, nonatomic) NSString *property;

- (void) method;

@end

7. Populate the MyClass.m with the following:

#import "MyClass.h"

@implementation MyClass

- (void) method {
    NSLog(@"In method now");
}

@end

8. Populate the UsingObjC-Bridging-Header.h with the following:

#import "MyClass.h"

9. To use the Objective-C class that you have added to your project, add the following statements in bold to the ViewController.swift file:

    override func viewDidLoad() {
        super.viewDidLoad()

        // create an instance of the class
        var myClass: MyClass = MyClass()

        // set its property
        myClass.property = "some random strings here"

        // call its method
        myClass.method()
        
        // retrieve its property
        println(myClass.property)

    }

Sunday, September 28, 2014

Swift - Using Selector in Swift

In Objective-C, you often encounter methods that accepts a Selector as the argument. A good example is the NSTimer's NSTimer.scheduledTimerWithTimeInterval() method:

- (void)onTimer {
}

    [NSTimer scheduledTimerWithTimeInterval:0.05
                                     target:self
                                   selector:@selector(onTimer)
                                   userInfo:nil
                                    repeats:YES];   


A selector is basically a name of a method that will be executed by another method. In Objective-C, to pass in a selector argument you use the @selector() keyword together with the name of the method. 

In Swift, you can simply pass in the name of the method as a string, like this:

func onTimer() {
}

        NSTimer.scheduledTimerWithTimeInterval(0.05,
            target:self,
            selector:"onTimer",
            userInfo:nil,
        repeats:true)

Wednesday, June 04, 2014

The Swift Programming Language - Lesson #2 - Arrays

In this lesson, you will learn how to create and use arrays in Swift.

Arrays

An array is a collection of objects - and the ordering of objects in an array is important. The following statement shows an array containing 3 items: 

var OSes = ["iOS", "Android", "Windows Phone"]

In Swift, you create an array using the [] syntax. The compiler automatically infers the type of items inside the array; in this case it is an array of String elements.

Note that if you attempt to insert an element of a different type, like this:

var OSes = ["iOS""Android""Windows Phone", 25]

The compiler will assume the elements inside the array to be of protocol type AnyObject (which is similar to id in Objective-C and System.Object in .NET), which is an untyped object.

In general, most of the time you want your array to contain items to be of the same type, and you can do so explicitly like this:

var OSes:String[] = ["iOS", "Android", "Windows Phone"]

This forces the compiler to check the types of elements inside the array and flag an error when it detects otherwise.

The following example shows an array of integers:

var numbers = [0,01,2,3,4,5,6,7,8,9]

To retrieve the items inside an array, specify its 0-based index, like this:

var item1 = OSes[0]   // "iOS"
var item2 = OSes[1]   // "Android"
var item3 = OSes[2]   // "Windows Phone"

To insert an element at a particular index, use the insert() function:

OSes.insert("BlackBerry", atIndex: 2)

item3 = OSes[2]       // "BlackBerry"
var item4 = OSes[3]   // "Windows Phone"

Note that in the above function call for insert(), you specify the parameter name - atIndex. This is known as an external parameter name and is usually needed if the creator of this function dictates that it needs to be specified.

We shall talk more about this when we discuss functions. 

To change the value of an existing item in the array, specify the index of the item and assign a new value to it:

OSes[3] = "WinPhone"

To append an item to an array, use the append() function:

OSes.append("Tizen")

Alternatively, you can also see the += operator to append to an array, like this:

OSes += "Tizen"

You can append an array to an existing array, like this:

OSes += ["Symbian", "Bada"]

To know the length of an array, use the count property:

var lengthofArray = OSes.count

To check if an array is empty, use the isEmpty() function:

var arrayIsEmpty = OSes.isEmpty

You can also remove elements from an array using the following functions:

OSes.removeAtIndex(3)              // removes "WinPhone"
OSes.removeLast()                  // removes "Bada"

OSes.removeAll(keepCapacity: true) // removes all element

For the removeAll() function, it clears all elements in the array. If the keepCapacity parameter is set to true, then the array will maintain its size.

Mutabilities of Arrays

When creating an array, its mutability (its ability to change its size after it has been created) is dependent of you using either the let or var keyword. If you used the let keyword, the array is immutable (its size cannot be changed after it has been created) as you are creating a constant. If you used the var keyword, the array is mutable (its size can be changed after its creation) as you are now creating a variable.

OK for today! Look out for the next lesson soon!

Tuesday, June 03, 2014

The Swift Programming Language - Lesson #1

Apple has surprised quite a number of developers at WWDC 2014 yesterday with the announcement of a new programming language - Swift. The aim of Swift is to replace Objective-C with a much more modern language and at the same time without worrying too much about the constraints of C compatibility. Apple itself touted Swift as the Objective-C without the C.

For developers already deeply entrenched in Objective-C, it is foreseeable that Objective-C would still be the supported language for iOS and Mac OS X development in the near and immediate future. However, signs are all pointing that Apple is intending Swift as the future language of choice for iOS and Mac development.

While groans can be heard far and near about the need to learn another programming language, such is the life of a developer. The only time you stop learning is when the end of the world is near (OK, you get the idea). So, in the next couple of weeks and months, I am going to walk you through the syntax of the language in bite-size format (so that you can probably read this on the train or on the bus home), and hopefully give you a better idea of the language.

So, let the journey begin!

Constants

In Swift, you create a constant using the let keyword, like this:

let radius = 3.45
let numOfColumns = 5

let myName = "Wei-Meng Lee"

Notice that there is no need to specify the data type -  they are inferred automatically. If you wish to declare the type of constant, you can do so using the : operator followed by the data type, like this:


let diameter:Double = 8;

The above statement declares diameter to be a Double constant. You want to declare it explicitly because you are assigning an integer value to it. If you don't do this, the compiler will infer and assume it to be an integer constant.

Variables

To declare a variable, you use the var keyword, like this:

var myAge = 25
var circumference = 2 * 3.14 * radius

Once a variable is created, you can change its value:

circumference = 2 * 3.14 * diameter/2

In Swift, values are never implicitly converted to another type. For example, suppose you are trying to concatenate a string and the value of a variable. In the following example, you need to explicitly use the String() function to convert the value of circumference to a string value before concatenating it with another string:

var strResult = "The circumference is " + String(circumference)

Including Values in Strings

One of the dreaded tasks in Objective-C is to insert values of variables in a string. In Swift, this is very easy using the \() syntax. The following example shows how:

var strName = "My name is \(myName)"

You can also rewrite the earlier statement using the following statement:

var strResult = "The circumference is \(circumference)"

OK for now, stay tuned for the next lesson!

Wednesday, March 26, 2014

Comparing Pebble and Android Wear

A number of readers have wrote in to ask me how does Android Wear compare to Pebble. Here is a list of items that I have compiled which I hope would be useful for those of you wanting to choose a wearable platform to develop for.

Note that this is a work-in-progress and I welcome your feedbacks if any of the items listed here is inaccurate. I will update it as more information is made available. 



Android Wear




Pebble








Android Wear is a modified version of the Android OS adapted for wearable devices sich as watches. The primary function of Android Wear is as an extension of your Android device – displaying notifications and allowing users to interact with the device through voice navigation on the wearable device.

The Pebble is a smart watch that allows you to write apps that run on the watch as well as on your mobile device. It displays notifications from your device.

Pebble also allows companion apps running on the mobile devices to provide additional functionalities to the apps running on the Pebble watch.
  
Availability
Devices such as Moto 360 and LG G watches have been announced; availability not known yet
Pebble and Pebble Steel
Manufacturer support
Motorola, LG, Asus, HTC, Samsung, and more
Pebble
Interaction with users
Voice control and touch screen
Four buttons – Up, Select, Down, and Back
Device Network connectivity
Classic Bluetooth, Bluetooth Low Energy (LE)
Classic Bluetooth, Bluetooth Low Energy (LE)
Hardware Features
Not clear at this moment
Accelerometer, ambient light sensor, magnetometer
Standalone apps
Not available in the Developer Preview release
Yes, watchface apps and watch apps can run standalone on the watch
Companion apps on the mobile device
Android Wear devices require apps on the mobile device to send notifications to it
Companion apps on the mobile device can send notifications as well as provide additional functionalities such as Web services access, location-based services, etc
Connection to mobile device
Requires connection to a Android device
Optional; connection to a mobile device is only required for the installation of watchfaces and watch apps;
Color Screen
Yes
No, only black and white support
Touch Screen
Yes
No
Platform support
Android only
iOS and Android
Supports notifications
Yes. The primarily function of Android Wear is to display notifications from the Android device
Yes. Displays notifications from the iOS and Android device
SDK
Android Wear Developer Preview + Android SDK
Pebble SDK
Programming language support
Java
C (native apps), Javascript, Objective C and Java (Pebble Mobile apps)
Smartphone compatibility
Works with Android 4.3 and above devices. At this moment, Android Wear can only connect to phone devices; but Google has announced that the Android Wear Developer Preview release will be updated to support non-phone devices as well
Works with iOS 6.0 and newer and Android 4.0 and newer devices