Post

Replies

Boosts

Views

Activity

An error occurred while trying to call the requested method validateMetadata. (1272)
I'm getting this error when attempting to upload an iOS app to iTunes Connect. I've tried using Transporter, and get the same result.I've also tried uploading a new version of an app that uploaded correctly in November and got the same result.Does anyone have any suggestions for possible causes for this error?thanks,
6
0
5.5k
Nov ’21
Having problems with a SwiftUI checkbox binding I'm implementing...
Hello folks, I'm attempting to implement some swiftUI UI code to support filtering of a list. One part of the filtering involves displaying one checkbox for each case/value of an enum (TangleType below) TangleFilter is a model class that includes an array of TangleTypeFilter objects (each owning a single bool value and a binding) Expected behaviour: when user taps a checkbox, the checkbox toggles the display and the filter model object toggles its value. Actual behaviour: the model is updating appropriately, however the UI is not updating. (the single filter below the list does in fact behave correctly any and all guidance greatly appreciated Mike struct ContentView: View {     @State var isChecked: Bool = false     @ObservedObject var filter = TangleFilter()     @ObservedObject var singleFilter: TangleTypeFilter     init() {         self.singleFilter = TangleTypeFilter(tangleType: .grid)     }     var body: some View {         VStack{             List(filter.tangleTypes, id: \.self) {tangleTypeFilter in                 HStack {                     // when uncommented the following line returns the following                     // compile error:                     // Use of unresolved identifier '$tangleTypeFilter' //                    CheckBox(isChecked: $tangleTypeFilter.isChecked)                     CheckBox(isChecked: tangleTypeFilter.binding)                     Text("checked? \(tangleTypeFilter.isChecked.description)")                 }             }             CheckBox(isChecked: $singleFilter.isChecked)         }     } } struct CheckBox: View {     @Binding var isChecked: Bool {         didSet {             print("setting isChecked: \(isChecked)")         }     }     var imageName: String {         return isChecked ? "checkmark.square" : "square"     }     var body: some View {         Button(action: {             self.isChecked.toggle()         }) {             Image(systemName: self.imageName)         }     } } enum TangleType: String, Codable, CaseIterable {     static let filterArray: [TangleTypeFilter] = {         var result: [TangleTypeFilter] = []         for tangleType in TangleType.allCases {             result.append(TangleTypeFilter(tangleType: tangleType))         }         return result     }()     case grid     case row } class TangleFilter: ObservableObject {     @Published var tangleTypes: [TangleTypeFilter] = TangleType.filterArray } class TangleTypeFilter: ObservableObject {     var tangleType: TangleType     @Published var isChecked: Bool     lazy var binding: Binding<Bool> = Binding(get: {         return self.isChecked     }, set: {         self.isChecked = $0     })     init(tangleType: TangleType) {         self.tangleType = tangleType         self.isChecked = false     } } extension TangleTypeFilter: Hashable {     static func == (lhs: TangleTypeFilter, rhs: TangleTypeFilter) -> Bool {         return lhs.tangleType == rhs.tangleType     }     func hash(into hasher: inout Hasher) {         hasher.combine(tangleType)     } }
6
1
2.9k
Jan ’21
A syntax error I'm not understanding...
I'm defining a typealias for a set, and then creating an extension for the new typealias. When I do this, I'm getting an odd syntax error. Any/all guidance appreciated. typealias IntSet = Set&lt;Int&gt; extension IntSet { func aFunction() -&gt; Set&lt;String&gt; { let array: [String] = self.map { "\($0)" } return Set(array) } } At the return line, I get the following syntax error: Cannot convert return expression of type 'Set&lt;Int&gt;' to return type 'Set&lt;String&gt;' Even if I replace the return line with the following, I get the same compile error return Set("array")
3
0
812
May ’24
My SwiftUI code is becoming un-SwiftUI-y. I'm looking to make things right again.
I have a singleton instance of a class that (among other things) is managing which subset of words will be available to users. The contents of availableWords will always be a subset of words and is always a function of three userDefaults that are bound to user settings (using @AppStorage) I could dynamically reconstruct availableWords every time it is needed, but it will be read much more frequently than it changes. Because of this, I want to cache the updated list every time a user changes one of the settings that will change its contents. But the only way I can see to do this is to create an update function and rely on the UI code to call the function any time a user updates one of the settings that will require availableWords to be updated. And this feels more like something out of UIKit. Do any of you see a better way of managing the updates of availableWords? class WordsManager { static let shared = WordsManager() let words: Words // defined in init var availableWords: Words // updated anytime scriptPickers, languageChoice or cardPile changes @AppStorage("scriptPickers") var scriptPickers: ScriptPickers = ScriptPickers.defaultDictionary @AppStorage("languageChoice") var languageChoice: LanguageChoice = .all @AppStorage("cardPile") var cardPile: CardPile = .allRandom func updateAvailableWords() { var result = words.filtered(by: cardPile.wordList) let askIdentifiers = languageChoice.askLanguages let answerIdentifiers = languageChoice.answerLanguages result = result.matching(askIdentifiers: askIdentifiers, answerIdentifiers: answerIdentifiers) self.availableWords = result } // other stuff }
3
0
805
May ’24
How might I get didSet behaviour on an AppStorage var?
I've defined a value stored in UserDefaults. In a view struct I have code that can successfully update the stored value. I've also added an @AppStorage var in an instance of a class, that can read this value and run business logic that depends on the current stored value. But what I really want to do, is have code in my class that gets automatically called when the value stored in UserDefaults gets updated. Basically I want to do this: @AppStorage("languageChoice") var languageChoice: LanguageChoice = .all { didSet { print("hello") } } Unfortunately didSet closures in @AppStorage vars do not appear to get called :-( My clumsy attempts to use combine have all ended in tears from the compiler. Any/all suggestions are greatly appreciated. thanks, Mike
3
0
1.2k
Jun ’24
Trying to better understand CGAffineTransform.... and need a bit of guidance.
I have a CoreImage pipeline and one of my steps is to rotate my image about the origin (bottom left corner) and then translate it. I'm not seeing the behaviour I'm expecting, and I think my problem is in how I'm combining these two steps. As an example, I start with an identity transform (lldb) po transform333 ▿ CGAffineTransform - a : 1.0 - b : 0.0 - c : 0.0 - d : 1.0 - tx : 0.0 - ty : 0.0 I then rotate 1.57 radians (approx. 90 degrees, CCW) transform333 = transform333.rotated(by: 1.57) - a : 0.0007963267107332633 - b : 0.9999996829318346 - c : -0.9999996829318346 - d : 0.0007963267107332633 - tx : 0.0 - ty : 0.0 I understand the current contents of the transform. But then I translate by 10, 10: (lldb) po transform333.translatedBy(x: 10, y: 10) - a : 0.0007963267107332633 - b : 0.9999996829318346 - c : -0.9999996829318346 - d : 0.0007963267107332633 - tx : -9.992033562211013 - ty : 10.007960096425679 I was expecting tx and ty to be 10 and 10. I have noticed that when I reverse the order of these operations, the transform contents look correct. So I'll most likely just perform the steps in what feels to me like the incorrect order. Is anyone willing/able to point me to an explanation of why the steps I'm performing are giving me these results? thanks, mike
3
0
569
Jan ’25
Looking to tweak default behaviour for a SwiftUI NavigationView in a TabView on iPad (in Portrait orientation)
At the top level, my app has a tab bar. the second tab's root view is a list view. When a user taps an item in the list, the app presents a detail view for the list item. The problem I'm currently having is the behaviour the first time the user taps the second tab's button in the tab bar (when running on an iPad in portrait. There is a navBar at the top, but the screen is otherwise empty. (tapping the left button on the navBar shows the list view, which allows the user to select an item which populates the main detail view) Is there some way (in swfitUI) to force the list view to show when in portrait? Alternatively/additionally, is there someway to present some instructional view in the otherwise empty view. (It doesn't appear to be creating a standard detail view here until the user exposes the list and picks an item) Here is some sample code that demonstrates what I'm describing. thanks in advance for any assistance! Mike import SwiftUI struct ContentView: View {     var body: some View {         TabView(){             FirstTabView()                 .tabItem {                     Text("First")                 }                 .tag(0)             SecondTabView()                 .tabItem {                     Text("Second")                 }                 .tag(1)         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()         .previewDevice(PreviewDevice(rawValue: "iPad8,1"))     } } struct FirstTabView: View {     var body: some View {         Text("First View")     } } struct SecondTabView: View {     var body: some View {         NavigationView {             NavigationLink(destination: Text("Detail View")) {                 Text("SummaryView")             }             .navigationBarTitle("Navigation")         }     } }
2
0
926
Aug ’21
A potentially dumb questions about swift (and dateFormatters)
I seem to recall hearing that DateFormatters are (or were) expensive to instantiate. With this in mind, I tried a small experiment with the following code: class MyClass { &#9;&#9;static let df = DrawingCellView.dateFormatter     static var dateFormatter: DateFormatter {         let result = DateFormatter()         result.dateFormat = "yyyy-MM-dd"         return result     } &#9;&#9;func dateText() -> String { &#9;&#9;&#9;&#9;return MyClass.dateFormatter.string(from: Date()) &#9;&#9;} When I put a breakpoint in the dateFormatter code, it fires each time I use it. However if I instead use df, the breakpoint only fires once. Does this make sense? If so, is this the recommended way to construct a runOnce static constant declaration/assignment? thanks! Mike
2
0
686
Jan ’21
UIHostingController question...
I have a SwiftUI view that works as expected in a full SwiftUI context. But I now need to use it in a UIViewController. It mostly works, but I'm trying to expose an @State var out to the viewController, and it only ever returns the initial value. Any guidance for how best to pass out this @State var? I could make it be a binding, but in my pure SwiftUI code, it works fine as @State (ie EditorView's container view does not need to know about sliderVal) thanks, in advance, for any suggestions import SwiftUI import UIKit class ViewController: UIViewController { var host: UIHostingController<EditorView>? override func viewDidLoad() { super.viewDidLoad() host = .init(rootView: EditorView()) guard let host = host else { return } addChild(host) host.view.translatesAutoresizingMaskIntoConstraints = false view.addSubview(host.view) host.didMove(toParent: self) } @IBAction func helloTapped(sender: UIButton) { guard let sliderValue = host?.rootView.sliderVal else { return } print("UIKit sliderValue: \(sliderValue)") } } struct EditorView: View { @State var sliderVal: Double init(sliderVal: Double? = nil) { _sliderVal = State(initialValue: sliderVal ?? 7) } var body: some View { VStack { Slider(value: $sliderVal, in: 1...10) Text("sliderVal: \(sliderVal)") } } } (NOTE: in order to see this code snippet in action you will need to create a button in the storyboard and link it to helloTapped)
2
0
1.4k
Jan ’24
Unexpected behaviour when attempting to decode enum keys from a JSON dictionary
This first code works fine decoding json. static let localizationsDictText = """ { "en" : { "string" : "Cat" }, "fr" : { "string" : "Chat"} } """ struct Localization: Codable, Equatable { let string: String } typealias LocalizationsDict = [String: Localization] func testExample() throws { let text = Self.localizationsDictText let data = text.data(using: .utf8, allowLossyConversion: false) let localizationsDict = try JSONDecoder().decode(LocalizationsDict.self, from: data!) XCTAssertEqual(localizationsDict.keys.count, 2) } But then I try to create a modified version of the above, only changing the type of the LocalizationsDict key from String to an enum: enum Language: String, CaseIterable, Codable { case en = "en" case fr = "fr" } typealias LocalizationsDict2 = [Language: Localization] func testExample2() throws { let text = Self.localizationsDictText let data = text.data(using: .utf8, allowLossyConversion: false) let localizationsDict = try JSONDecoder().decode(LocalizationsDict2.self, from: data!) XCTAssertEqual(localizationsDict.keys.count, 2) } and the JSONDecoder line throws an exception: testExample2(): failed: caught error: "typeMismatch(Swift.Array<Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array<Any> but found a dictionary instead.", underlyingError: nil))" Any suggestions as to why switching from [String: Localization] to [Language: Localization] might cause JSONDecode() to treat it like an array? Thanks in advance for any guidance.
2
0
749
Mar ’24
Looking to use @AppStorage, but avoid depending on UserDefaults.standard
I am using @AppStorage in a model object (see code below that works as expected). class ModelObject { static let shared = ModelObject() @AppStorage("enhanced") var scriptPickers: Bool = true var defaultDependentValue: String { scriptPickers ? "Enhanced" : "NOT enhanced" } } struct ContentView: View { @AppStorage("enhanced") var scriptPickers: Bool = true var body: some View { VStack { Toggle(isOn: $scriptPickers, label: { Text("userDefault val") }) Text("value: \(ModelObject.shared.defaultDependentValue)") } } } Now I want to test my model object in a way that will allow me to use a mock instance of UserDefaults, but am having trouble with the syntax. I tried adding a userDefaults var, and referring to the var in the @AppStorage class ModelObject { static let shared = ModelObject() let userDefaults: UserDefaults init(userDefaults: UserDefaults = .standard) { self.userDefaults = userDefaults } @AppStorage("enhanced", store: userDefaults) var scriptPickers: Bool = true var defaultDependentValue: String { scriptPickers ? "Enhanced" : "NOT enhanced" } } However I can't find a way to avoid the syntax error this generates: Cannot use instance member 'userDefaults' within property initializer; property initializers run before 'self' is available Any guidance on how I might be able to: continue using @AppStorage be able to test my class in a way that doesn't force me to use UserDefaults.standard thanks, in advance, Mike
2
0
593
May ’24
How can I subscribe to changes to an @AppStorage var...
From what I've read, @AppStorage vars should be @Published, however the following code generates a syntax error at extended's .sink modifier: Cannot call value of non-function type 'Binding<Subject>' class LanguageManager: ObservableObject { @Published var fred = "Fred" @AppStorage("extended") var extended: Bool = true private var subscriptions = Set<AnyCancellable>() init() { $fred .sink(receiveValue: {value in print("value: \(value)") }) .store(in: &subscriptions) $extended .sink(receiveValue: {value in print("value: \(value)") }) .store(in: &subscriptions) } Does anyone know of a way to listen for (subscribe to) changes in @AppStorage values? didSet works in for a specific subset of value changes, but this is not sufficient for my intended use.
2
0
1.7k
Jun ’24
Struggling to add a test target to an existing project in Xcode
Sorry if this question is too vague, however I've tried this multiple times and see the same result. I'm pretty sure I'm doing something wrong, but don't know what. I have a Multiplatform (iOS and macOS) project that builds, and runs I add a new target of type Unit Test Bundle I click the diamond in the margin beside the XCTestCase declaration at the top of the new Test file The target project builds, then Xcode says 'Testing...' and it stays like this forever. I've also tried creating a new scheme that targets the target created in the above steps. attempting to run my tests behaves the same. The top status bar will get stuck saying 'Testing...' and never get anywhere. I'm pretty sure this is something basic. thanks, in advance for any guidance. Mike
2
0
1.3k
Nov ’24
Adding logging to a SwiftUI View's body var
Pretty sure this is a no-no, but asking just in case there's an easy way to make this work struct DocumentContentView: View { private static let logger = Logger( subsystem: "mySubsystem", category: String(describing: Self.self) ) var body: some View { VStack { Text("Hello") logger.trace("hello") } } } This code generates the following compile error at the logger.trace line buildExpression is unavailable: this expression does not conform to View I suspect every line of the body var (or any @ViewBuilder - designated code?) needs to 'return' a View. Is this correct? or more importantly any work arounds other than putting some/all of the view contents in a. func()?
2
1
2.6k
Dec ’24
Is it possible to make GeometryReader less vertically greedy?
I must be missing something here. I want to put a landscape image in a geometry reader that contains a ZStack that contains an image and an overlay centred on top of the Image. I would like the ZStack and GeoReader's sizes to be the size of Image. (ie I want geometry.size to be the size of the image, which can be used to control the offset of the overlay's position.) Unfortunately the ZStack also includes the space above the image (ie the top safeArea) and the GeometryReader also includes all the space below the Image. (so geometry.size.height is greater than the height of Image) I've gone down rabbit holes of adding other items above/below, but I don't seem to be able to prevent the GeometryReader from being vertically greedy. eg the Text(" ") above the ZStack in the VStack solves the ZStack claiming the top safe area. But adding Text(" ") below the ZStack does not prevent the GeometryReader from claiming more vertical space below the image. Any/all guidance greatly appreciated. struct ContentView: View { var body: some View { VStack { // Text(" ") GeometryReader { geometry in ZStack { Image( uiImage: .init(imageLiteralResourceName: "LandscapeSample") ) .resizable() .aspectRatio(contentMode: .fit) Text("Hello, world!") .background(.white) } .background(.red) } .background(.blue) // Text(" ") } } }
2
0
449
Jan ’25