Development Specification
- Xcode v9.1
- Swift 3
- Support: iphone 8/7/6/SE or plus, iPad and iPad Pro
- Latest commit on Oct 19
Screenshot
1 List of technologies
1.1 Property Observers
1 | var selectedShapeTag: Int = 0 { |
Property observers observe and respond to changes in a property’s value.
Here the variable “selectdShapeTag” is the property being observed.The observer’s body is call every time a property’s value is set, it doesn’t matter if its value changed or not.
There are two kinds of observers willSet and didSet. each property can have either one or both of these observers.Here when you change the selectedShapeTag vale, for example into #3, before the new value is stored into selectedShapeTag, the shapeButtone which has a tag number 3 in an array, is set to Selected.
Then the variable selectedShapedTag become 3.
Immediately after this, the didSet snippet is called, so if the new tase is equal to the old tag, we change the old button’s state into unselected.
1.2 Delegation
Delegation is a pattern that enables one class to hand off its task to another class.
Defining a protocol that encapsulate the responsibilities.
Below is my Setting View controller.
The Delegation is used to respond to a particular action, here it is
dissmissView
1 | import UIKit |
Then the CanvasViewController will adopt and confirm the protocol, and he got the object sent by the settingViewController as self
, so he got the setting values of every thing: the brush size, color, transparency etc. then all the current setting can be updated.
1 | extension CanvasViewController: SettingsViewControllerDelegate { |
2 Parts could be improved
2.1 Method Size
The codes are too big sometimes, it’s not easy to read and maintain.
Also my code is not neat enough, I think it is because I’m not able to get the most from various beautiful features of Swift language. So just learn more and do more.
2.2 comment
- Another thing is annotation or comment. I don’t have much sense of when and how to make a useful comment.
This need to do more pratices and I wish somene can shore something about that.
3 Apple Human Interface Guideline
- User Standard gestures
- Avoid using standard gestures to perform nonstandard actions.
- Don’t block systemwide screen-edge gestures.
- Offer shortcut gestures to supplement, not replace, interface-based navigation and actions.
- Use multi-finger gestures to enhance the experience of some apps.
4 iOS Life Cycle
- Five different Execution states of an App:
Not running / Inactive / Active / Background / Suspended - Something about the App Termination
- Misbehaving or not responding
- Suspended
- user can terminate
- Apps must be prepared for termination to happen at any time and should not wait to save user data.
5 Comparison between Swift and C#
BASICS
Const is let and var is still var
1 | # Swift |
1 |
|
COLLECTIONS
1 | # Swift |
1 |
|
Protocol
1 | protocol Nameable { |
1 |
|
Lambdas and Closures
1 | # Closure Expression Syntax |
1 |
|
What I learned
- How to use SQLiteBrowser to view your CoreData
Download and install from http://sqlitebrowser.org
Insert follow code to show db file e.g. “AppName”.sqlite
1 | let storeUrl = appDelegate.persistentContainer.persistentStoreCoordinator.persistentStores.first?.url |
file:///Users/xxx/Library/Developer/CoreSimulator/Devices/95E79F65-8DC5-4200-83C7-CE443685D25E/data/Containers/Data/Application/35C1939D-DD2F-4B4E-AF70-6489047977A2/Library/Application%20Support/SmartPen.sqlite
Open Termial and locate to that file
cd /Users/xxx/Library/Developer/CoreSimulator/Devices/95E79F65-8DC5-4200-83C7-CE443685D25E/data/Containers/Data/Application/35C1939D-DD2F-4B4E-AF70-6489047977A2/Library/Application%20Support
run
open .
open that foldercopy that three data file to Desktop then in sqlite brower click open DataBase.