Post

Replies

Boosts

Views

Activity

Reply to Using Combine-Future to Fetch Server Data
The following works. import UIKit import Combine class ViewController: UIViewController { // MARK: - Variables private var cancellableSet: Set<AnyCancellable> = [] override func viewDidLoad() { super.viewDidLoad() let _ = Future<[DataModel], Error> { [weak self] promise in guard let strongSelf = self else { return } let url = URL(string: "https://api.github.com/repos/ReactiveX/RxSwift/events")! URLSession.shared.dataTaskPublisher(for: url) .timeout(2.0, scheduler: DispatchQueue.global(qos: .background)) .retry(3) .map { $0.data } .decode(type: [DataModel].self, decoder: JSONDecoder()) .sink(receiveCompletion: { (completion) in print("I'm done: \(completion)") }, receiveValue: { dataModels in for model in dataModels { print("\(model.id) \(model.type)") } promise(.success(dataModels)) }) .store(in: &strongSelf.cancellableSet) } } } I wonder why it doesn't work if I use ViewModel?
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’21
Reply to UILabel with superscript text
override func viewDidLoad() { super.viewDidLoad() let text = "1:47PM" if let regularFont = UIFont(name: "Helvetica", size: 20.0), let subscriptFont = UIFont(name: "TamilSangamMN", size: 12.0) { let attString:NSMutableAttributedString = NSMutableAttributedString(string: text, attributes: [.font: regularFont]) attString.setAttributes([.font: subscriptFont, .baselineOffset: 6], range: NSRange(location: text.count - 2, length: 2)) label.attributedText = attString } }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to Combining More Than Four @Published Variables in Combine?
I guess it goes like the following. Publishers.CombineLatest4($variable0, $variable1, $variable2, $variable3) .combineLatest($variable4) .combineLatest($variable5) .sink { completion in } receiveValue: { response0, response1 in let variable = response0.0 let variable4 = response0.1 let variable5 = response1 let v0 = variable.0 let v1 = variable.1 let v2 = variable.2 let v3 = variable.3 }.store(in: &cancellables) It's kind of odd.
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Using URLSession in Combine
Okay... The solution to my question is use of the Future guy. class APIClient: NSObject { var cancellables = [AnyCancellable]() @Published var models = [MyModel]() func fetchData(urlStr: String) -> Future<[MyModel], Error> { return Future<[MyModel], Error> { [weak self] promise in guard let url = URL(string: urlStr) else { return promise(.failure("Failure" as! Error)) } guard let strongSelf = self else { return } URLSession.shared.dataTaskPublisher(for: url) .map { $0.data } .decode(type: [MyModel].self, decoder: JSONDecoder()) .replaceError(with: []) .sink { completion in if case .failure(let error) = completion { promise(.failure(error)) } } receiveValue: { promise(.success($0)) } .store(in: &strongSelf.cancellables) } } } class ViewModel: NSObject { @IBOutlet var apiClient: APIClient! var cancellables = Set<AnyCancellable>() @Published var dataModels = [MyModel]() func getGitData() -> Future<[MyModel], Error> { let urlStr = "https://api.github.com/repos/ReactiveX/RxSwift/events" return Future<[MyModel], Error> { [weak self] promise in guard let strongSelf = self else { return } strongSelf.apiClient.fetchData(urlStr: urlStr) .sink { completion in if case .failure(let error) = completion { promise(.failure(error)) } } receiveValue: { promise(.success($0)) print("view model: \($0.count)") } .store(in: &strongSelf.cancellables) } } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Nov ’21
Reply to Using Combine-Future to Fetch Server Data
I've removed the comment.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to Using Combine-Future to Fetch Server Data
The following works. import UIKit import Combine class ViewController: UIViewController { // MARK: - Variables private var cancellableSet: Set<AnyCancellable> = [] override func viewDidLoad() { super.viewDidLoad() let _ = Future<[DataModel], Error> { [weak self] promise in guard let strongSelf = self else { return } let url = URL(string: "https://api.github.com/repos/ReactiveX/RxSwift/events")! URLSession.shared.dataTaskPublisher(for: url) .timeout(2.0, scheduler: DispatchQueue.global(qos: .background)) .retry(3) .map { $0.data } .decode(type: [DataModel].self, decoder: JSONDecoder()) .sink(receiveCompletion: { (completion) in print("I'm done: \(completion)") }, receiveValue: { dataModels in for model in dataModels { print("\(model.id) \(model.type)") } promise(.success(dataModels)) }) .store(in: &strongSelf.cancellableSet) } } } I wonder why it doesn't work if I use ViewModel?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Dec ’21
Reply to UILabel with superscript text
override func viewDidLoad() { super.viewDidLoad() let text = "1:47PM" if let regularFont = UIFont(name: "Helvetica", size: 20.0), let subscriptFont = UIFont(name: "TamilSangamMN", size: 12.0) { let attString:NSMutableAttributedString = NSMutableAttributedString(string: text, attributes: [.font: regularFont]) attString.setAttributes([.font: subscriptFont, .baselineOffset: 6], range: NSRange(location: text.count - 2, length: 2)) label.attributedText = attString } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Where do I start?
You should start by reading the Swift Programming Language.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Getting ignored by support
Call them up?
Replies
Boosts
Views
Activity
Nov ’21
Reply to Alnahda Dubai (Call) Girls +971589930402
Don't you have something else to have fun?
Replies
Boosts
Views
Activity
Nov ’21
Reply to Hottest 0529579100 Dubai Call Girls, Indian Call Girls in Dubai
Are you having fun?
Replies
Boosts
Views
Activity
Nov ’21
Reply to Combining More Than Four @Published Variables in Combine?
I guess it goes like the following. Publishers.CombineLatest4($variable0, $variable1, $variable2, $variable3) .combineLatest($variable4) .combineLatest($variable5) .sink { completion in } receiveValue: { response0, response1 in let variable = response0.0 let variable4 = response0.1 let variable5 = response1 let v0 = variable.0 let v1 = variable.1 let v2 = variable.2 let v3 = variable.3 }.store(in: &cancellables) It's kind of odd.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Combining More Than Four @Published Variables in Combine?
I thought let publishers = Publishers.CombineLatest4($variable0, $variable1, $variable2, $variable3) .combineLatest($variable4) .combineLatest($variable5) could work. But it doesn't.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Combining More Than Four @Published Variables in Combine?
Actually, no...
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Combining More Than Four @Published Variables in Combine?
Maybe, subscribing to an array of them?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Question free app
It depends on the purpose of your app. After a trial period, if the app has no features to use, then it will be rejected for sure.
Replies
Boosts
Views
Activity
Nov ’21
Reply to how to use Apple Pay without backend server or stripe.
To my knowledge, Apple Pay is not a payment processing service system. It's a mediator or a digital wallet that stores privacy data and allows the user to make a payment through a third-party processing system. So the answer to your question is no, I suppose.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How do I check personal information before enrollment?
Go to Apple Developer and click on Membership after signing in.
Replies
Boosts
Views
Activity
Nov ’21
Reply to Using URLSession in Combine
Okay... The solution to my question is use of the Future guy. class APIClient: NSObject { var cancellables = [AnyCancellable]() @Published var models = [MyModel]() func fetchData(urlStr: String) -> Future<[MyModel], Error> { return Future<[MyModel], Error> { [weak self] promise in guard let url = URL(string: urlStr) else { return promise(.failure("Failure" as! Error)) } guard let strongSelf = self else { return } URLSession.shared.dataTaskPublisher(for: url) .map { $0.data } .decode(type: [MyModel].self, decoder: JSONDecoder()) .replaceError(with: []) .sink { completion in if case .failure(let error) = completion { promise(.failure(error)) } } receiveValue: { promise(.success($0)) } .store(in: &strongSelf.cancellables) } } } class ViewModel: NSObject { @IBOutlet var apiClient: APIClient! var cancellables = Set<AnyCancellable>() @Published var dataModels = [MyModel]() func getGitData() -> Future<[MyModel], Error> { let urlStr = "https://api.github.com/repos/ReactiveX/RxSwift/events" return Future<[MyModel], Error> { [weak self] promise in guard let strongSelf = self else { return } strongSelf.apiClient.fetchData(urlStr: urlStr) .sink { completion in if case .failure(let error) = completion { promise(.failure(error)) } } receiveValue: { promise(.success($0)) print("view model: \($0.count)") } .store(in: &strongSelf.cancellables) } } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Nov ’21