iphones/Beacons & swift
What will be covered
TODAY
- Intro to XCode
- A simple BLE project: http://git.io/ve9gE
- Using the Storyboard designer (maybe)
NEXT WEEK (or so)
- Handling REST with Alamofire and SwiftyJSON
- Cocoa Pods
XCode
-
Check out Sample Code at http://git.io/ve9gE
-
This code needs changes (as it is pre Swift 1.2)
Swift Design principals
- Better NIL value handling via optionals and strict initialization
- Strongly (statically I suppose) typed
- Use ObjC & Swift within the same project (via Bridging Headers)
- Functions are first-class citizens; Closures
- Memory Management and memory saftey (no GC, no ARC, no unsafe pointer casting)
- Assertions
Swift optionals
scala has it too
f: a function which returns an Array or NIL
func f(arr: [Int]) -> [Int]? { if (arr.count < 1) { return nil } else { return arr }
}
Swift optionals
Array? is of type OPTIONAL (yes that's a type) Use UNWRAPPING via ! to get the actual value
var i = f([1,2])![0] //OK - unwrapping works var i = f([1])![0] //Booom - f returns NIL
Swift optionals
Typical pattern.
if (let i = f([1]) { println(i.description) }
You can also use
if (f(<some array>) != nil) { // do something }
Delegate pattern
Delegation is a design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type.
Application Delegate. - viewDidLoad CLLocationManagerDelegate.
There are important events in the life of your application that happen out of its direct control. These include things like launching and terminating. Your application needs to know when these things happen or are about to happen, so the iPhone OS will automatically notify your AppDelegate by calling the appropriate method (e.g. applicationDidFinishLaunching, applicationWillTerminate). That's the main purpose of the AppDelegate.
Things that should be run once a BLE event is triggered.
Core-location Delegate
Responding to Location Events Pausing Location Updates Responding to Region Events Responding to Authorization Changes
Deplyoing to Appstore
This app will not be accepted by Apple.
BCNs
By Steffo Weber
BCNs
- 556