Skip to content

Instantly share code, notes, and snippets.

View alvaroroyo's full-sized avatar
🤠
Working from home

Alvaro Royo alvaroroyo

🤠
Working from home
View GitHub Profile
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let products: [SKProduct] = response.products
}
func fetchProducts() {
let identifiers: Set<String> = ["com.app.premium.monthly","com.app.premium.annual"]
let productsRequest = SKProductsRequest(productIdentifiers: identifiers)
productsRequest.delegate = self
productsRequest.start()
}
//SKProductsRequestDelegate
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
let products: [SKProduct] = response.products
variables:
ITUNESCONNECT_USER: "user@user.com"
ITUNESCONNECT_PASS: ""
stages:
- archive
archive_project:
stage: archive
script:
stages:
- build
build_project:
stage: build
script:
- xcodebuild test -workspace <Project_Name>.xcworkspace -scheme <Schema_Name> -destination 'platform=iOS Simulator,name=iPhone 8'
tags:
- ios_12-2
- xcode_10-2-1
extension Array where Element: Decodable {
enum ArrayDecodeError: String, Error {
case nilData
}
static func decode(with data: Data?) throws -> [Element] {
guard let data ​= data else { throw ArrayDecodeError.nilData }
let arr = try JSONDecoder().decode([Failable<Element>].self, from: data)
let elements = arr.compactMap{ $0.obj }
fileprivate struct Failable<T: Decodable>: Decodable {
let obj:T?
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.obj = try? container.decode(T.self)
}
}
public func encode(to encoder: Encoder) throws {
var baseContainer = encoder.container(keyedBy: BaseContainer.self)
try baseContainer.encode(self.address, forKey: .address)
var dataContainer = baseContainer.nestedContainer(keyedBy: DataContainer.self, forKey: .data)
try dataContainer.encode(self.name, forKey: .name)
try dataContainer.encode(self.age, forKey: .age)
extension Person {
public init(from decoder: Decoder) throws {
let baseContainer = try decoder.container(keyedBy: BaseContainer.self)
self.address = try baseContainer.decode(String.self, forKey: .address)
let dataContainer = try baseContainer.nestedContainer(keyedBy: DataContainer.self, forKey: .data)
extension Person {
private enum BaseContainer: String, CodingKey {
case address
case data
case otherData = "Other_Data"
}
private enum DataContainer: String, CodingKey {
case name
struct Person: Codable {
var id: Int
var name: String
var age: Int
var address: String
}