Skip to content

Commit

Permalink
add/#119 ObservablePattern 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JinUng41 committed Jul 4, 2024
1 parent 3f13dd3 commit 981c850
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
14 changes: 13 additions & 1 deletion KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
DE254ACB2C311DC200A4015E /* Pretendard-Black.otf in Resources */ = {isa = PBXBuildFile; fileRef = DE254AC22C311DC200A4015E /* Pretendard-Black.otf */; };
DE254ACC2C311DC200A4015E /* Pretendard-Thin.otf in Resources */ = {isa = PBXBuildFile; fileRef = DE254AC32C311DC200A4015E /* Pretendard-Thin.otf */; };
DE8247FD2C36E7C7000601BC /* MoyaLoggingPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8247FC2C36E7C7000601BC /* MoyaLoggingPlugin.swift */; };
DE8248002C36E857000601BC /* ObservablePattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8247FF2C36E857000601BC /* ObservablePattern.swift */; };
DED5DBEC2C345210006ECE7E /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED5DBEB2C345210006ECE7E /* BaseViewController.swift */; };
DED5DBEE2C34529A006ECE7E /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED5DBED2C34529A006ECE7E /* BaseView.swift */; };
DED5DBF02C345317006ECE7E /* BaseCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED5DBEF2C345317006ECE7E /* BaseCollectionViewCell.swift */; };
Expand Down Expand Up @@ -111,6 +112,7 @@
DE254AC22C311DC200A4015E /* Pretendard-Black.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Black.otf"; sourceTree = "<group>"; };
DE254AC32C311DC200A4015E /* Pretendard-Thin.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-Thin.otf"; sourceTree = "<group>"; };
DE8247FC2C36E7C7000601BC /* MoyaLoggingPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoyaLoggingPlugin.swift; sourceTree = "<group>"; };
DE8247FF2C36E857000601BC /* ObservablePattern.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservablePattern.swift; sourceTree = "<group>"; };
DED5DBEB2C345210006ECE7E /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
DED5DBED2C34529A006ECE7E /* BaseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = "<group>"; };
DED5DBEF2C345317006ECE7E /* BaseCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -192,10 +194,10 @@
78B9286A2C29402C006D9942 /* KkuMulKum */ = {
isa = PBXGroup;
children = (
DE8247FB2C36E7BB000601BC /* Network */,
DE254AA12C31106700A4015E /* Application */,
DE254AA22C31107700A4015E /* Source */,
DE254AA32C31107C00A4015E /* Resource */,
DE8247FB2C36E7BB000601BC /* Network */,
);
path = KkuMulKum;
sourceTree = "<group>";
Expand Down Expand Up @@ -224,6 +226,7 @@
78B928742C29402E006D9942 /* Assets.xcassets */,
78B928762C29402E006D9942 /* LaunchScreen.storyboard */,
78B928792C29402E006D9942 /* Info.plist */,
DE8247FE2C36E846000601BC /* ObservablePattern */,
DED5DBEA2C345202006ECE7E /* Base */,
DE254AA62C3118B300A4015E /* Extension */,
DE254AB52C3119BC00A4015E /* Util */,
Expand Down Expand Up @@ -279,6 +282,14 @@
path = Network;
sourceTree = "<group>";
};
DE8247FE2C36E846000601BC /* ObservablePattern */ = {
isa = PBXGroup;
children = (
DE8247FF2C36E857000601BC /* ObservablePattern.swift */,
);
path = ObservablePattern;
sourceTree = "<group>";
};
DED5DBEA2C345202006ECE7E /* Base */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -430,6 +441,7 @@
DE254AAC2C31192400A4015E /* UILabel+.swift in Sources */,
DE254AB72C3119D000A4015E /* ReuseIdentifiable.swift in Sources */,
DE254AB42C31199B00A4015E /* UITextField+.swift in Sources */,
DE8248002C36E857000601BC /* ObservablePattern.swift in Sources */,
DE254AAA2C31190E00A4015E /* UIStackView+.swift in Sources */,
DED5DBF02C345317006ECE7E /* BaseCollectionViewCell.swift in Sources */,
DE254AA82C3118EA00A4015E /* UIView+.swift in Sources */,
Expand Down
34 changes: 34 additions & 0 deletions KkuMulKum/Resource/ObservablePattern/ObservablePattern.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// ObservablePattern.swift
// KkuMulKum
//
// Created by 김진웅 on 7/4/24.
//

import Foundation

class ObservablePattern<T> {
var value: T {
didSet {
listener?(value)
}
}

private var listener: ((T) -> Void)?

init(_ value: T) {
self.value = value
}

func bind(_ listener: @escaping (T) -> Void) {
self.listener = listener
}

func bind<Object: AnyObject>(with object: Object, _ listener: @escaping (Object, T) -> Void) {
self.listener = { [weak object] value in
guard let object else { return }
listener(object, value)
}
}
}

0 comments on commit 981c850

Please sign in to comment.