Skip to content

Instantly share code, notes, and snippets.

View hsleedevelop's full-sized avatar
🔥

HS Lee hsleedevelop

🔥
View GitHub Profile
func makeAPICall() -> Result<String?, NetworkError> {
let path = "https://jsonplaceholder.typicode.com/todos/1"
guard let url = URL(string: path) else {
return .failure(.url)
}
var result: Result<String?, NetworkError>!
let semaphore = DispatchSemaphore(value: 0)
URLSession.shared.dataTask(with: url) { (data, _, _) in
if let data = data {
@hsleedevelop
hsleedevelop / LikeReshapes.swift
Last active May 15, 2019 11:45
likeReshapes
let half = round(list.count.d / 2.d).i
let reshapes = (list[0...half].map { $0 }, list[half..<list.count].map { $0 })
self.list = (0..<half).flatMap { i -> [HomeDataType] in [reshapes.0[i]] + (i < reshapes.1.count ? [reshapes.1[i]] : []) }
action ...
Specify one or more actions to perform. Available actions are:
build Build the target in the build root (SYMROOT). This is the default action, and is used if no action is given.
build-for-testing Build the target and associated tests in the build root (SYMROOT). This will also produce an xctestrun file in
the build root. This requires specifying a scheme.
analyze Build and analyze a target or scheme from the build root (SYMROOT). This requires specifying a scheme.
@hsleedevelop
hsleedevelop / findnotusingfiles.txt
Last active May 14, 2019 02:13
find not using files in Xcode project
https://stackoverflow.com/a/52825714/3374327
Assuming your MyProject.xcodeproj is in your working directory, and all your sources are in or below your working directory, you could use a hack* like this to look for .m files that are not part of any target:
find . -name "*.m" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep "{} in Sources" MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1"
Once you remove the files from the project, you can remove them -- and other objc source files that are no longer referenced from your project -- from your git repo using this similar script:
find . -name "*.[hm]" -exec basename '{}' \; | xargs -I '{}' sh -c 'grep {} MyProject.xcodeproj/project.pbxproj > /dev/null; echo "$?\c"; echo " {}"' | grep "^1" | cut -c3- | xargs -I '%' find . -name '%' -exec git rm '{}' \;
* hack in the sense that it depends on implementation details of the Xcode file format.
@hsleedevelop
hsleedevelop / gist:1ceba0d4c039f0e6bdbbf8c904fa9a85
Last active May 8, 2019 10:53
jenkins configuration - build
#source ~/.bash_profile
export FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT=120
export TERM=xterm-256color
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
bundle install
bundle exec pod install --repo-update
1... Why is UIScrollView leaving space on top
With Storyboard- Goto view controller > Attribute Inspector > Uncheck Adjust Scroll View Insets property
With Code- For extra space set viewController property automaticallyAdjustsScrollViewInsets to NO, by default it is YES.
self.automaticallyAdjustsScrollViewInsets = false;
scroller.contentInset = UIEdgeInsetsZero;
scroller.scrollIndicatorInsets = UIEdgeInsetsZero;
scroller.contentOffset = CGPointMake(0.0, 0.0);
@hsleedevelop
hsleedevelop / multipleBindingAtOnce.swift
Last active April 8, 2019 11:08
multiple Binding At Once Example
let binder: (Observable<Bool>) -> Disposable = { obs in
return obs.bind(to: self.tableView.rx.printing)
}
let bindCurry: (Observable<Bool>) -> (Binder<Bool>) -> Observable<Bool> = { obs in
return { binder in
obs.bind(to: binder).disposed(by: self.disposeBag)
return obs
}
}
@hsleedevelop
hsleedevelop / json.swift
Created March 21, 2019 07:45 — forked from chriseidhof/json.swift
Reflection
import Cocoa
struct Person {
var name: String = "John"
var age: Int = 50
var dutch: Bool = false
var address: Address? = Address(street: "Market St.")
}
struct Address {
//캐릭터 변경, 넽 변경 에 따른 홈-전체 리로드
guard let reachabilityObservable = try? DefaultReachabilityService.shared().reachability.asObservable() else {
return
}
Observable.combineLatest(UserDataManager.shared.currentCharacter, reachabilityObservable, viewModel.currentTabEditEvent.startWith(nil))
.distinctUntilChanged({ (lhs, rhs) -> Bool in
return lhs.2 != rhs.2 || lhs.1.reachable != rhs.1.reachable || lhs.0 != rhs.0
})
.map { [weak self] args -> (CharacterType?, ReachabilityStatus, RxTimeInterval) in
@hsleedevelop
hsleedevelop / delaySubscription_example.swift
Last active January 4, 2019 05:25
delay subscription
.flatMapFirst { args -> Observable<(CharacterType?, ReachabilityStatus)> in
let delay = self.editSection == nil ? 0 : 0.75
return Observable.just(args).delaySubscription(RxTimeInterval(delay), scheduler: MainScheduler.instance)
}