Skip to content

Instantly share code, notes, and snippets.

View zapping0320's full-sized avatar

John DongHyun Kim zapping0320

View GitHub Profile
@zapping0320
zapping0320 / customView2.swift
Created May 20, 2021 00:24
xib를 이용한 CustomView
import UIKit
class CustomView2: UIView {
private let xibName = "CustomView2"
override init(frame: CGRect) {
super.init(frame: frame)
self.commonInit()
}
@zapping0320
zapping0320 / customview1.swift
Created May 20, 2021 00:16
xib 없는 custom uiview
import UIKit
class CustomView1: UIView {
let titleLabel:UILabel = {
let label = UILabel()
label.frame = CGRect(x: 0, y: 0, width: 60, height: 25)
label.translatesAutoresizingMaskIntoConstraints = false
label.textAlignment = .center
label.text = "라벨"
@zapping0320
zapping0320 / exceptionDate.swift
Created November 19, 2020 02:54
날짜 형식에 대한 예외 처리
jsonEncoder.dateEncodingStrategy = .formatted(DateFormatter.iso8601Full)
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
@zapping0320
zapping0320 / loadJsonFile.swift
Created November 19, 2020 02:49
json string을 구조체로 decode
func loadJsonFile() -> bigSur?{
let jsongDecoder = JSONDecoder()
do {
guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return nil}
let fileURL = documentDirectoryUrl.appendingPathComponent("sampleData.json")
let jsonData = try Data(contentsOf: fileURL, options: .mappedIfSafe)
let decodedBigSur = try jsongDecoder.decode(bigSur.self, from: jsonData)
@zapping0320
zapping0320 / saveJsonData.swift
Created November 19, 2020 02:47
구조체를 json으로 바꿔서 저장
func saveJsonData(data:bigSur) {
let jsonEncoder = JSONEncoder()
do {
let encodedData = try jsonEncoder.encode(data)
print(String(data: encodedData, encoding: .utf8)!)
guard let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return }
let fileURL = documentDirectoryUrl.appendingPathComponent("sampleData.json")
@zapping0320
zapping0320 / jsonString.txt
Created November 19, 2020 02:44
구조체를 json으로 변환하여 출력
{
"result": "success",
"message": "sentMsg",
"data": {
"bsList": [
{
"bs_id": 1,
"bs_addr2": "222",
"bs_key": "333",
"bs_addr1": "111",
@zapping0320
zapping0320 / BigSur.swift
Created November 19, 2020 02:17
Codable을 상속 받은 구조체
import Foundation
struct bigSur : Codable {
let message: String
let req_id:String
let result:String
let data : bslistOut
}
struct bslistOut : Codable {