Skip to content

Instantly share code, notes, and snippets.

@justinlee
justinlee / .swift
Created July 24, 2018 09:08
extension Encodable
extension Encodable {
subscript(key: String) -> Any? {
return dictionary[key]
}
var data: Data {
return try! JSONEncoder().encode(self)
}
var dictionary: [String: Any] {
return (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] ?? [:]
}
@justinlee
justinlee / .json
Created July 11, 2018 05:49
json data sample
"TicketApp" : {
"CustomScheme": {
"URL": {
"htpps://ticket.interpark.com/Genre/GenreHome":{
"ParsingType":"hasPrefix",
"Title":"장르",
"Type":"URL_Load",
"LoadClass":"TicketGenreViewController",
"BottomMenu":{
"Animation":true
@justinlee
justinlee / ObjectiveC.m
Last active June 18, 2018 08:33
Objective-C 코드에서 Swift코드 사용.
TestSwift * testSwift = [[TestSwift alloc] init];
[testSwift PrintString];
NSLog(@"결과값 : %d",[testSwift addX:2 Y:3]);
@justinlee
justinlee / TestSwift.swift
Last active June 18, 2018 08:33
Objective-C에서 Swift 코드 사용.
import UIKit
class TestSwift: NSObject {
@objc(PrintString)
func PrintString() {
print("Test Swift is Working")
}
@objc(addX:Y:)
func add(x: Int, y: Int) -> Int {
@justinlee
justinlee / CustomAddProtocol.h
Created June 18, 2018 08:07
CustomAddProtocol 프로토콜
#import <Foundation/Foundation.h>
@protocol CustomAddProtocol <NSObject>
- (id)addValue:(id)value;
@end
@justinlee
justinlee / CustomNumberClass.m
Created June 18, 2018 08:05
CustomNumberClass에 CustomAddProtocol 프로토콜 적용.
#import <Foundation/Foundation.h>
#import "CustomAddProtocol.h"
@interface CustomNumberClass : NSObject<CustomAddProtocol>
@property (nonatomic,retain) NSNumber * value;
- (instancetype)initWithInteger:(NSInteger)value;
- (id)addValue:(id)value;
@end
@justinlee
justinlee / StackClass.m
Created June 18, 2018 07:59
StackClass에 ObjectType에 Protocol을 따르는 Class만 사용하도록 강제하는 경우.
#import <Foundation/Foundation.h>
@interface StackClass<T:id<CustomAddProtocol>> : NSObject
@property (nonatomic,retain) NSMutableArray *items;
- (void)push:(T)value;
- (T)pop;
@end
#import "StackClass.h"
CustomNumberClass * numberA = [[CustomNumberClass alloc] initWithInteger:10];
CustomNumberClass * numberB = [[CustomNumberClass alloc] initWithInteger:20];
StackClass<CustomNumberClass *> * stack = [[StackClass alloc]init];
[stack push:numberA];
[stack push:numberB];
NSLog(@"%@",stack.items);
@justinlee
justinlee / StackClass.m
Last active June 18, 2018 07:49
ObjectiveC Generics
#import <Foundation/Foundation.h>
@interface StackClass<T> : NSObject
@property (nonatomic,retain) NSMutableArray *items;
- (void)push:(T)value;
- (T)pop;
@end
#import "StackClass.h"
@justinlee
justinlee / AVPlayerView_AVPlayerViewController_Example.m
Last active May 10, 2018 06:20
AVPlayerView와 AVPlayerViewController의 예제
/*
MPMoviePlayerViewController의 경우 iOS 9.0에서 DEPRECATED 되었다.
하지만 동작엔 문제가 없다가 실제로 iOS 11.3에서 동작이 안되게 되었기에 문제가 발생하게 되었다.
MPMoviePlayerViewController 대신 AVPlayer와 AVPlayerViewController를 사용해 수정해 줘야 한다.
*/
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>