Post

Replies

Boosts

Views

Activity

Detect multiple NFC tag types including NDEF?
Hi, Relatively new to NFC, but have prototyped a reader/writer. I have a bunch of MiFare Classic, but these aren't being detected so I assume they're unsupported? I also have some MiFare DESFire tags, which are detected using an NFCTagReaderSession, but not NFCNDEFReaderSession. tag reader became active tag reader did detect tags [tag] Optional(CoreNFC.NFCTag.miFare(<NFCMiFareTag: 0x282ab8b40>)) family:  NFCMiFareFamily 2020-07-26 15:50:38.651264+0100 Vendor[815:147466] [CoreNFC] 00000002 80ae4900 -[NFCTagReaderSession setAlertMessage:]:92  (null) tag read invalidated Is it possible to detect any tags, and then work out if they're NDEF capable or not? It seems we have to use a NFCTagReaderSession or NFCNDEFReaderSession, which means choosing physical tag type way ahead of writing an app? I guess I'm confused with NDEF v 'native' types, as described in the Apple docs. Even though the tag claims to support NDEF, it would be useless in a real world situation (if I implemented an app using the more general NFCNDEFReaderSession). Especially if you can't just overwrite a tag with NDEF data. This seems weird, as everything (incl WWDC) talks about starting out with using the NDEF implementation. Do tags need to be correctly formatted at the factory, either NDEF or MiFare? thanks,
0
0
705
Jul ’20
Compile error, doing calculations in View body
Hi, I'm trying to show a number of buttons of a certain relative size to the screen width. For now I'm hard-coding the number of buttons, just to get the collection view wrap style working. I'm getting the Xcode error: The compiler is unable to type-check this expression in reasonable time It seems obvious that doing the indexing calculations probably cause the problem. But I don't know how to do that calculation once per iteration, and store the value. It worked fine, compiled, and ran in preview mode a couple of times. Then with no changes it just stopped compiling, and Xcode gave the error. Any suggestions as to what can I do? Eventually I want to use the index calculation to subscript an array value. struct collectionView: View {     let totalElements = 5     let rowCount = 2     let rowLength = 3     var body: some View {         GeometryReader<AnyView> { geometry in             return AnyView(                 VStack(alignment: .leading) {                     ForEach(0..<self.rowCount) { rowIndex in                         HStack {                             ForEach(0..<self.rowLength) { elementIndex in                                 if ((rowIndex * self.rowLength) + elementIndex < self.totalElements) {                                     Button(action: {                                         print(msg: "\((rowIndex * self.rowLength) + elementIndex)")                                     }) {                                         Text("\( (rowIndex * self.rowLength) + elementIndex)")                                     }                                     .background(Color.purple)                                     .foregroundColor(Color.white)                                 }                             } // ForEach elementIndex                         } // HStack                     } // ForEach rowIndex                 } // VStack             ) // AnyView         } // GeometryReader     } }
3
0
465
Jul ’20
Single ObservableObject fronting the data model?
Hi, I watched the WWDC20 'Data Essentials in SwiftUI'. Around 12:00 it's explained (from transcript): You can model your data using value type and manage its lifecycle inside effect with a reference type. For example you can have a single observable object that centralizes your entire data model and is shared by all your view. Like in the diagram here, this gives you a single place for all your logic making it easy to reason about all the possible state and mutation in your app. What's meant by this, as a pattern? If I have Movies, Actors, Reviews, as models, how is it proposed that I create a proxy class that makes some properties of the models observable? Or, I create a single 'global' observable object (class) which has properties of Movies, Actors, Reviews (structs)? So the class is effectively a shell or holding object for my models? Such that Movies (a list of Movie structs) becomes a @Published property. thanks,
0
0
246
Jul ’20
Behaviour of dispatch group tasks with completions?
Hi, I have pseudo code for a repeating task of work: api_call("/status") { 	if response.statusCode == 418 { 		api_call("/rotate-credentials") { ... } 	} 	else { 		doSomeWork() 	} 	sleep(60) 	api_call("/status") } I want to make a call to /status roughly every 60 seconds, but if the response is a 418 then I want to complete a call to /rotate-credentials before continuing with the next status request. There are other api calls going on as well, triggered by user interaction. These other api calls should wait until the /status call is completed in full (including if a credential rotation is triggered). This implies a serial queue? But that won't wait for the completions to finish, so I should be looking at a dispatch group enter(), leave() and wait() right? I can't find/understand from the docs where completion handlers go, in terms of execution, relative to dispatch queues. So where is the completion handler execution of the subsequent call to /rotate-credentials ? If I wrap the status call in a dispatch group, is the rotate-credentials completion handler execution covered by this group? So no further tasks will begin until that task is complete? The credentials are used for digest signing of http requests, hence why I want to pause other api calls until the rotate-credentials is complete. thanks,
2
0
760
Jun ’20
Best approach to optionally show sign-up view, with SwiftUI?
Hi,I need logic like this, using SwiftUI:if userHasAccount { showDashboardView() } else { showSignupView() // blocks progress until complete showDashboardView() }I'm unsure where/how the best place and approach for this is.My instincts say that the scene() method in SceneDelegate would be the place to conditionally alter the rootView. But then how do I, on signup completion, disgard the signup root view and transition to the dashboard view?I've read quite a few approaches to conditional views implement AnyView casting or using Group, within the default contentView. This seems a little bit of a hack?thanks,
2
0
1.4k
Jun ’20
Best app format for cron type execution?
Hi,For a while I have used a bash script, executed by cron, to warn me of low battery levels on bluetooth devices (mouse/keyboard). I have the threshold set high enough that I can get to the end of the day until I need to charge, as we all know you can't use the mouse and charge 🙂A few people asked me about it, then a few more. I am usually doing iOS stuff, so am not too familiar with OSX apps. What would be the best packing format (app, stay as a bash script, etc) to be able to distribute this functionality (free) to non-technical people? I mean to rewrite the bash version into Swift, and making use of IOKit or something.The tidied up bash version is here: https://github.com/thisdougb/MagicPowerAlertBut I could imagine some UI that lets you confgure when the alert happens, and what the threshold should be. Nothing more.Is this the sort of thing Automator is for (never used it) ?thanks,
0
0
318
Apr ’20
Allow var to hold parent or sub-class type
Hi,My motivation is mocking objects for unit testing, but the problem seems more that I'm not understanding the language (inheritance?) itself. So I condensed things down (hopefully) into a single Swift command line tool, to show the essence of what I'm stuck with. I can see what the problem is, I just don't know the right (Swift-like) way to approach it.On line 80 I want to set a properly of the sub-class MockNetworkHandler, but I can't because the property is not visible (compiler error). I realise that mockClient.netHandler is of type NetworkHandler, which is (I believe) why the compiler says no.Why does mockClient.netHandler take a sub-class type, yet not let me access that types properties?What is the best approach to get functionality that lets me do simple logic like this, in a mocked class?thanks,// // main.swift // Demo // // Created by Doug Bridgens on 16/04/2020. // Copyright © 2020 Doug Bridgens. All rights reserved. // import Foundation // my principle class for network handling public class NetworkHandler { public init() { } func websiteStatus(_ fullURL: String, _ completion: @escaping (Int) -> Void) { if let url = URL(string: fullURL) { var request = URLRequest(url: url) request.httpMethod = "HEAD" let task = URLSession.shared.dataTask(with: request, completionHandler: { (data, response, error) in if let httpResponse = response as? HTTPURLResponse { completion(httpResponse.statusCode) } }) task.resume() } } } // I mock this class to be able to shortcut the async dataTask() call, and // to be able to control the network responses (for unit testing) public class MockNetworkHandler: NetworkHandler { // this var should let me switch on/off the network for unit tests var websiteActive = true public override init() { super.init() } override func websiteStatus(_ fullURL: String, _ completion: @escaping (Int) -> Void) { if websiteActive { completion(801) // 801 just to differentiate from a real request in this example } else{ completion(901) // 901 just to differentiate from a real request in this example } } } public class AppClient { var netHandler: NetworkHandler? public init() { netHandler = NetworkHandler() } public convenience init(mockNetHandler: MockNetworkHandler) { self.init() netHandler = mockNetHandler } } // normal app flow let client = AppClient() let statusCompletion: (Int) -> Void = { status in print("status \(status)") } // uncomment to make real requests //client.netHandler?.websiteStatus("https://apple.com", statusCompletion) // flow using mocked network handler, this is simulating what I want to do in unit tests let mockClient = AppClient(mockNetHandler: MockNetworkHandler()) // PROBLEM: the following line is a compiler error: Value of type 'NetworkHandler?' has no member 'websiteActive' //mockClient.netHandler.websiteActive = false mockClient.netHandler?.websiteStatus("https://apple.com", statusCompletion) dispatchMain() // stay alive, allowing async calls to complete
7
0
610
Apr ’20
Networking in iOS app v Mac command line tool
Hi,I'm using SPM to extract the networking component of an app into a package. Part of what I thought I'd get, by doing that, is to be able to build a command-line-tool to make testing quicker. The tool is essentially like a ping command built on top of the network package, that I can use to test the networking logic while I simulator various conditions with the Cloud API (offline, busy, etc).However, it's the first command line tool I've built. And I'm learning that I need to learn more about command line tool building 🙂This is a fairly standard method to set the stateUpdateHandler (in my networking package). It works fine in the iOS simulator, but doesn't get called when used in the command line tool. But, I call a .send() after starting the connection and in both cases the data is sent to the remote side ('nc -l 80').Can anyone recommend some good resources to learn, that will help me figure out why the below doesn't work on the command line?thanks func startConnection() { guard let connection = connection else { return } // A handler that receives connection state updates. connection.stateUpdateHandler = { newState in switch newState { case .setup: print("setup: \(connection)") case .preparing: print("preparing: \(connection)") case .ready: print("established: \(connection)") case .waiting(let error): print("\(connection) waiting with \(error)") case .failed(let error): print("\(connection) failed with \(error)") default: break } } connection.start(queue: .main) }
9
0
2.2k
Mar ’20
Signing git commits
Hi,I have commit signing setup automatically through the git (cli) and Atom (IDE). I've been searching, but can't find that it's possible with Xcode. I find it a bit wierd that Apple dev's internally don't use commit signing.At the moment I'm using a Terminal window to manage git interactions (and get my commits signed). It's quite a bit of friction.Anything on the horizon with Xcode for commit signing?cheers,
0
2
680
Mar ’20