This document shows the pull requests submitted by Yu Chao throughout GSoC 2017.
Also, this is the link to the documentation of the project.
Pull requests completed in GSoC 17:
This document shows the pull requests submitted by Yu Chao throughout GSoC 2017.
Also, this is the link to the documentation of the project.
Pull requests completed in GSoC 17:
class DatabaseAccessor { | |
// The instance of DatabaseAccessor | |
static let sharedInstance = DatabaseAccessor() | |
// Private initializer to avoid instancing by other class. | |
private init() {} | |
/* ... */ | |
} |
class DatabaseAccessor { | |
static let sharedInstance = DatabaseAccessor() | |
private init() {} | |
// The instance of the SQLite database | |
private var mainDB: FMDatabase? | |
public func initializeDatabase() { | |
let databasePath = (dirPath as NSString).appendingPathComponent("database.sqlite") as NSString | |
CREATE TABLE `Contact` ( | |
`ID` INTEGER NOT NULL UNIQUE, | |
`Name` VARCHAR NOT NULL, | |
`Phone` INTEGER NOT NULL UNIQUE, | |
`City` VARCHAR NOT NULL, | |
PRIMARY KEY(`ID`) | |
); |
struct Contact { | |
var id: Int | |
var name: String | |
var phoneNumber: Int | |
var city: String | |
} |
func addContact(_ contact: Contact) { | |
let queryString = "INSERT INTO Contact (ID, Name, Phone, City) VALUES (\(contact.id), \(contact.name), \(contact.phoneNumber), \(contact.city))" | |
mainDB!.executeUpdate(queryString, withArgumentsIn: nil) | |
} |
func updateContact(_ contact: Contact) { | |
let queryString = "UPDATE Contact SET Name = \(Contact.name), Phone = \(Contact.phoneNumber), City = \(Contact.city) WHERE ID = \(Contact.id)" | |
mainDB!.executeUpdate(queryString, withArgumentsIn: nil) | |
} |
func searchContactByID(_ id: Int) -> Contact? { | |
let queryString = "SELECT * FROM Contact WHERE ID = \(id)" | |
// Execute query and save the results. | |
let queryResults: FMResultSet? = mainDB?.executeQuery(queryString, withArgumentsIn: nil) | |
// Check if there are results. | |
if queryResults?.next() == true { | |
let contactName = queryResults!.string(forColumn: "Name") | |
let contactPhone = Int(queryResults!.int(forColumn: "Phone")) |
let moveAction = SKAction.move(to: CGPoint(x: 10.0, y: 20.0), duration: 5.0) | |
spriteNode.run(moveAction) |
let scaleAction = SKAction.scale(to: 2.0, duration: 3.0) | |
spriteNode.run(scaleAction, completion: { spriteNode.color = SKColor.red }) |