I'm thinking of using server-side validation of a receipt and in-app purchase, but I'm not sure how I can prevent a valid receipt from one device from being used illicitly on a different device. Then I started thinking about local validation, and realized I don't understand how it works there either. Yes, there is the "hash" in the receipt that uses the `UIDevice.current.identifierForVendor`, but if a device is jailbroken, can't it just patch a framework somewhere to return a bogus ID there, to match the one in the illicit receipt?
Post
Replies
Boosts
Views
Activity
I've been running my unit tests for a macOS app a lot. Every now and then it leaves a zombie running. I wouldn't care about the "Z" process in "ps ax" output, but it actually leaves an icon in the list of app icons that you see when you hit Command-Tab. These gradually accumulate and cannot be killed. It appears I need to restart my laptop to get rid of them. If anyone else has seen this and has a trick to get rid of them, please let me know.
I'm writing an app that uses CloudKit and also a local database (SQLite) so the app can function without internet. It's a challenge. I'm sure I'm re-inventing some wheels. I’m curious … anyone know of any good books about architecture or design patterns for this kind of thing?
I've watched a couple WWDC videos and I'm looking at the docs here: https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/supporting_drag_and_drop_in_collection_viewsI'm trying to implement dropping one item (a "file") unto another item (a "folder"), to move it into the folder. In my `collectionView(_:performDropWith)` I have:moveItemsInModel()
collectionView.deleteItems(at: [indexPathOfMovedFile])
let newDestinationIndexPath = // ... get index path for destination "folder" item in current model
let item = coordinator.items.first!.dragItem
let cell = collectionView.cellForItem(at: newDestinationIndexPath)! // This seems to work, gets the right cell
let imageView = cell.viewWithTag(self.imageViewTag) as! UIImageView
let rect = cell.convert(imageView.bounds, from: imageView)
coordinator.drop(item, intoItemAt: newDestinationIndexPath, rect: rect)My problem is that that last "drop" animation is animating to where it _was_. So if I move a file from before the folder, the animation slides the folder over and then drops to where it used to be.How do you do this? Is there example code somewhere?
I've got a UICollectionView and I'm trying to drag and drop items within the view (document items unto a folder item to move it to a folder). I implemented the `collectionView(_:itemsForBeginning:at:)` method and that gets called. I provide some drag items. The drag starts working but when I let go, the item animates back to it's original position, and nothing gets called. Why is it not dropping?
With a lot of traditional software you buy it once and then pay a lesser price for occasional major version updates. I kind of liked that model, but it's not directly supported by the app store. What is the recommended replacement - subscriptions? I can see a few ways to do it...1. A subscription (probably yearly). If the subscription expires, then the app could keep running but disable the new features added after the subscription expired. 2. Non-consumable IAP to enable the full features of each major version. So you'd have IAPs like "Full app version 1", "Full app version 2", ...3. Non-consumable IAP to enable features sets. Similar to #2 but instead of naming them by version I'd have to name groups of features.I guess I like #1 but it's new to me and I'm afraid it will scare away users because it's asking for a continuous payment.
Any one else noticing that when you have your device language as Spanish and region to US or Latin America, the AVSpeechSynthesisVoice speakes with a Spanish (Spain) accent? Seems like it's not picking the right voice. Ie, she pronounces "cinco" like "thinco".
The CGSize it returns is not the same one I get if I manually combine the rectangles for each line in the frame. I can get the same *width* (depending on which options I use with CTLineGetBounds), but never the same height. Does anyone know how it's calculating the height?Rob
Does anyone use this? I can't get it working. I'm talking about code in normal swift files, not playgrounds.Example:/// ![testdiagram](/Users/me/fullpathto/test-image.png)
/// ![test xcode image](http://devimages.apple.com.edgekey.net/assets/elements/icons/128x128/xcode.png)
///Neither one displays anything in the documentation popover or the Quick Help Inspector.The docs act like it works: https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/Images.html#//apple_ref/doc/uid/TP40016497-CH17-SW1A lot of my code would really benefit from diagrams in documentation. I'd love to be able to use this.
If I have a NavigationView, and a root view with an `Int` in its model, I can push other views with a Binding<Int> to that model, and if any of the pushed views updates the Int, everything re-renders as expected. But this only works if the root's model is State<Int>. If instead I have an `ObservableObject` with an Int property, it doesn't work. The first pushed view can change the Int, and it will update on screen, but further pushed Views do not update properly.Example code is below. It will work correctly if you use the commented-out lines with @State, instead of the @ObservedObject.As is, if you push two levels, and press "Increment Number", the screen doesn't update. (It does if you used @State at the root).Is this a known bug in SwiftUI? Shouldn't the Bindings work the same in both cases?class MyObject: ObservableObject {
@Published var number: Int = 1
}
struct ContentView: View {
// This one works
// @State private var number: Int = 1
// What about:
@ObservedObject var myObject: MyObject
var body: some View {
NavigationView {
VStack {
// Text("number: \(number)")
Text("number: \(myObject.number)")
NavigationLink(destination: PushedView(number: $myObject.number, pushLevel: 1)) {
Text("Push a View")
}
}
}
}
}
struct PushedView: View {
@Binding var number: Int
let pushLevel: Int
func incrementIt() {
number += 1
}
var body: some View {
VStack {
Text("Pushed View (level \(pushLevel))")
Text("number (via binding): \(number)")
Button(action: self.incrementIt) {
Text("Increment number")
}
NavigationLink(destination: PushedView(number: $number, pushLevel: pushLevel+1)) {
Text("Push a View")
}
}
}
}
Maybe this is too abstract or vague, but I'm wondering if the pattern is familiar to anyone.I have a color gradient editor view with a color picker subview that edits the color of the currently selected gradient stop. The design that makes sense to me is to have the gradient editor create a model object for it's color picker, a sort of adapter model that presents the current stop to that picker. (Color pickers take an ObservableObject model that conforms to a certain protocol.) But I can't seem to make this work in SwiftUI. It seems you can only have two kinds of model/state: global objects passed in to the root of the View hierarchy as @ObservedObject or @EnvironmentObject, or simple value types wrapped in @State.
Here's a weird one. Do I need to do something different to handle Pencil taps, or is this a bug?The following code shows a standard `Button`, and a few of custom Views called `SelectButtons`. The `Button` registers a tap with a Pencil or finger, as expected. The `SelectButtons` only work with my finger, on my iPad Pro. The Pencil taps don't register. struct ContentView: View {
let nums = [1,2,3]
@State var selected: Int = 1
var body: some View {
VStack {
Button(action: { print("Test button tapped")}) {
Text("Test button")
}
ForEach(nums, id: \.self) { num in
HStack {
SelectButton(num: num, current: self.$selected)
Text("Number \(num)")
}
}
}
}
}
struct SelectButton: View {
let num: Int
@Binding var current: Int
var isSelected: Bool { current == num }
var body: some View {
ZStack {
Circle().inset(by: 5).stroke()
Circle().inset(by: 7).fill(isSelected ? Color.blue : Color.clear)
}.frame(width:40, height:40)
.onTapGesture {
print("SelectButton.onTapGesture \(self.num)")
self.current = self.num
}
}
}
I've been using protocols to help model a hierarchy of different object types. As I try to convert my app to use SwiftUI, I'm finding that protocols don't work with the ObservableObject that you need for SwiftUI models. I wonder if there are some techniques to get around this, or if people are just giving up on "protocol oriented programming" when describing their SwftUI models? There is example code below. The main problem is that it seems impossible to have a View that with an model of protocol `P1` that conditionally shows a subview with more properties if that model also conforms to protocol `P2`.For example, I'm creating a drawing/painting app, so I have "Markers" which draw on the canvas. Markers have different properties like color, size, shape, ability to work with gradients. Modeling these properties with protocols seems ideal. You're not restricted with a single inheritance class hierarchy. But there is no way to test and down-cast the protocol...protocol Marker : ObservableObject {
var name: String { get set }
}
protocol MarkerWithSize: Marker {
var size: Float { get set }
}
class BasicMarker : MarkerWithSize {
init() {}
@Published var name: String = "test"
@Published var size: Float = 1.0
}
struct ContentView<MT: Marker>: View {
@ObservedObject var marker: MT
var body: some View {
VStack {
Text("Marker name: \(marker.name)")
if marker is MarkerWithSize {
// This next line fails
// Error: Protocol type 'MarkerWithSize' cannot conform to 'MarkerWithSize'
// because only concrete types can conform to protocols
MarkerWithSizeSection(marker: marker as! MarkerWithSize)
}
}
}
}
struct MarkerWithSizeSection<M: MarkerWithSize>: View {
@ObservedObject var marker: M
var body: some View {
VStack {
Text("Size: \(marker.size)")
Slider(value: $marker.size, in: 1...50)
}
}
}Thoughts?
I'm showing a popover with a short list of items to choose from. I'd like it to be pretty small, but I can't seem to control the size. It's too big, with a lot of extra space around its content. Anyone know how to control the popover size? VStack {
Button(action: { self.showPickerPopup = true }) {
Text(pickerTypeButtonText)
}.popover(isPresented: $showPickerPopup) {
List(self.choosablePickerTypes) { ptype in
Text(ptype.displayName).onTapGesture {
print("picked \(ptype)")
self.showPickerPopup = false
}
}.frame(minWidth: 0.0, minHeight: 0.0)
.frame(width: 200, height:300)
// ^^^-- these frame calls are ineffective
}
Spacer()
}
As an example, I wanted to know how to init a `Slider`. I know two ways of finding documentation, but they give different results. Is that a bug?1. Go to Xcode's Help menu > Developer Documentation, and search for "Slider". The docs for `init` do not describe the parameters.2. Control click on `Slider` in the code editor window, then "Jump to Definition", and I see the `Slider` struct and some extensions. There *are* documentation comments describing the parameters to `init`, like the `onEditingChanged` parameter.(Xcode version 11.3.1 (11C504))