Skip to content

Instantly share code, notes, and snippets.

View Rashidium's full-sized avatar

Rashid Ramazanov Rashidium

View GitHub Profile
@Rashidium
Rashidium / StringUtils.swift
Last active February 8, 2017 12:05
Vehicle Identification Number (VIN or chassis number) validation in Swift 3.0 with String extension
//
// Created by Rashid Ramazanov on 18/01/2017.
// Converted from Java snippet in https://en.wikipedia.org/wiki/Vehicle_identification_number#Example_Code
//
import Foundation
extension String {
var isValidChassisNo: Bool {
@Rashidium
Rashidium / User.swift
Created April 21, 2019 21:01
Decodable User struct
import Foundation
struct User: Decodable {
var username: String?
var name: String?
var surname: String?
var email: String?
var uid: String?
@Rashidium
Rashidium / Coupon.swift
Created April 21, 2019 21:06
Decodable Coupon struct
import Foundation
struct Coupon: Decodable {
var id: String = ""
var name: String = ""
var no: String = ""
var isOpen: Bool = false
var matches: [PMatches] = [] // PMatches is also a decodable struct.
{
"message" : "",
"status" : 1,
"data" : {
"uid" : "XXX-XXX-XXX",
"surname" : "Ramazanov",
"username" : "Rashid",
"email" : "[email protected]",
"name" : "Rashid",
}
{
"message": "",
"status": 0,
"data": {
"cpnid": "XXX-XXX-XXX",
"couponname": "29.Kupon",
"couponno": "29",
"iscouponopen" : false,
"matches": [
{
@Rashidium
Rashidium / PanpaResponse.swift
Last active April 21, 2019 21:36
Generic Response Decodable with T type.
import Foundation
struct PanpaResponse<T>: Decodable where T: Decodable {
private var statusInt: Int?
var status: Status {
if statusInt == 1 || statusInt == 0 {
return .success
}
return .failed
import Alamofire
...
func login() {
let urlStr = "\(serverUrl)\(EndpointTails.login.rawValue)"
AF.request(urlStr, method: .get).responseDecodable { (response: DataResponse<PanpaResponse<User>, AFError>) in
if let panpaResponse = response.value {
switch panpaResponse.status {
case .success:
guard let user: User = panpaResponse.data else { return }
print(user.username)
import Alamofire
...
private func getCoupon() {
let urlStr = "\(serverUrl)\(EndpointTails.group_last_coupon_one.rawValue)"
AF.request(urlStr, method: .get).responseDecodable { (response: DataResponse<PanpaResponse<Coupon>, AFError>) in
if let panpaResponse = response.value {
switch panpaResponse.status {
case .success:
guard let coupon: Coupon = panpaResponse.data else { return }
print(coupon.name)
{
"message": "",
"status": 0,
"coupon": {
"cpnid": "XXX-XXX-XXX",
"couponname": "29.Kupon",
"couponno": "29",
"iscouponopen" : false,
"matches": [
{
{
"message" : "",
"status" : 1,
"user" : {
"uid" : "XXX-XXX-XXX",
"surname" : "Ramazanov",
"username" : "Rashid",
"email" : "[email protected]",
"name" : "Rashid",
}