Post

Replies

Boosts

Views

Activity

Reply to Updating @State Variable Depending ForEach Row Selection
It seems that I have achieved my objective with the following. But I'm not sure if it's an efficient approach. import SwiftUI struct ContentView: View { @State var numbers = [2021, 9, 30] var body: some View { let firstLocalYear = 2021 let firstLocalMonth = 9 let firstLocalDay = 24 let firstLastDay = 30 NavigationView { List { Section(header: Text("Current month")) { ForEach(firstLocalDay ..< firstLastDay) { i in HStack { Text("\(firstLocalMonth)-\(i + 1)") Spacer() Button("Select") { self.numbers = [firstLocalYear, firstLocalMonth, i + 1] } NavigationLink( destination: TimeView(numbers: $numbers), label: { Text("") }) } } } } } } } struct TimeView: View { @Binding var numbers: [Int] var body: some View { HStack { Text(String(numbers[0])) Text(String(numbers[1])) Text(String(numbers[2])) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Observing Changes in Multiple @Published Variables at the Same Time?
I think I've figured it out for myself. It looks like I can use Publishers.CombineLatest(,) as follows. class ViewController: UIViewController { var cancellables = Set<AnyCancellable>() @Published var userText: String = "" @Published var passText: String = "" override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: usernameTextField) .sink(receiveValue: { (result) in if let myField = result.object as? UITextField { if let text = myField.text { self.userText = text } } }) .store(in: &cancellables) NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: passwordTextField) .sink(receiveValue: { (result) in if let myField = result.object as? UITextField { if let text = myField.text { self.passText = text } } }) .store(in: &cancellables) Publishers.CombineLatest($userText, $passText) .sink { (result0, result1) in print(result0, result1) }.store(in: &cancellables) } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Oct ’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 Does the banking application need to pay IAP?
If you allow them to make a purchase, you do have to use the IAP system, I suppose. I don't know if children are allowed to use this type of apps, though. See if you are eligible for a commission waiver.
Topic: App & System Services SubTopic: StoreKit Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Using TestFlight Before Submission?
I guess I can use Internal Testing.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’21
Reply to Value of type 'UIView?' has no member 'isEnabled'
I guess it's a dumb question. segmentNumber is not a bool object.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Value of type 'UIView?' has no member 'isEnabled'
What I should have done is the following. override func viewDidLoad() { super.viewDidLoad() cancellable = $segmentNumber.receive(on: DispatchQueue.main) .sink(receiveValue: { (number) in self.actionButton.isEnabled = (number == 0) ? false : true }) } Silly me...
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Practical Use of Combine's Subject
Oh, I see. Silly me... Thanks a lot.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Resources for development
Are you talking about Apple's marketing resources??
Topic: App & System Services SubTopic: Hardware Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Toggling Values on EnvironmentValue (EditMode)
Probably not because this EnvironmetValue is not dichotomous?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Changing a Status With @EnvironmentObject in Another View
Oops... Silly me... If it's logged in, I only show Text("Yes, I'm logged in")
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Updating @State Variable Depending ForEach Row Selection
It seems that I have achieved my objective with the following. But I'm not sure if it's an efficient approach. import SwiftUI struct ContentView: View { @State var numbers = [2021, 9, 30] var body: some View { let firstLocalYear = 2021 let firstLocalMonth = 9 let firstLocalDay = 24 let firstLastDay = 30 NavigationView { List { Section(header: Text("Current month")) { ForEach(firstLocalDay ..< firstLastDay) { i in HStack { Text("\(firstLocalMonth)-\(i + 1)") Spacer() Button("Select") { self.numbers = [firstLocalYear, firstLocalMonth, i + 1] } NavigationLink( destination: TimeView(numbers: $numbers), label: { Text("") }) } } } } } } } struct TimeView: View { @Binding var numbers: [Int] var body: some View { HStack { Text(String(numbers[0])) Text(String(numbers[1])) Text(String(numbers[2])) } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Combine with UITableView
I don't know if my approach in reading view model data is correct. At least, I don't think it's efficient in the view controller.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to Keeping Track of Text Changes over Two Text Fields
May I ask how I can receive a bool result in my view controller like func validateUser(username: String?, password: String?) -> AnyPublisher<Bool, Never> { if let username = username, let password = password { if !username.isEmpty && !password.isEmpty { // true } } } , please?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to Observing Changes in Multiple @Published Variables at the Same Time?
I think I've figured it out for myself. It looks like I can use Publishers.CombineLatest(,) as follows. class ViewController: UIViewController { var cancellables = Set<AnyCancellable>() @Published var userText: String = "" @Published var passText: String = "" override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: usernameTextField) .sink(receiveValue: { (result) in if let myField = result.object as? UITextField { if let text = myField.text { self.userText = text } } }) .store(in: &cancellables) NotificationCenter.default.publisher(for: UITextField.textDidChangeNotification, object: passwordTextField) .sink(receiveValue: { (result) in if let myField = result.object as? UITextField { if let text = myField.text { self.passText = text } } }) .store(in: &cancellables) Publishers.CombineLatest($userText, $passText) .sink { (result0, result1) in print(result0, result1) }.store(in: &cancellables) } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Oct ’21
Reply to Using URLSession in Combine
I wonder if I need to use Future to return data?
Topic: UI Frameworks SubTopic: UIKit Tags:
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
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