When developing a CloudKit application, the standard recommendation is to create an iCloud account for testing. That makes a lot of sense as I’d like to keep developing code far from my personal iCloud account. But the CloudKit Dashboard won’t let me view the private database for that account. What do other people do to check their work?* clarification: I mean on the development server, not the production server.
Post
Replies
Boosts
Views
Activity
in iOS 12, the default behaviour of Core Data is to create a sqlite database in Library/Application Support. The iOS Data Storage Guidelines tell us which direcotories are saved when a device is backed up or synced to iTunes, but it is silient about the Library and Library/Application Support folders.https://developer.apple.com/icloud/documentation/data-storage/index.html"1. Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud."I'm storing user-generated content using Core Data and the default persistent store, SQLite. Do I need to do something to ensure the database is automatically backed up by iCloud? I hope that includes iTunes syncing/backup by wire too.
I've got Yet Another Protocol Question. Sorry, folks.The Swift 5.1 manual describes creating a `Collection` where the `Element` is a simple protocol, but doesn't explain how to make a Collection where the Element is a protocol with an associatedtype. In my case it's a protocol `Playable` that requires conformance to `Identifiable`.I am fine with requiring the `Identifiable.ID` type to be `Int` for all types which adopt `Playable`, but I don't know how to express that qualification/requirement. The bits hit the fan when I try to declare something to be `[Playable]`.My playground code might make my question clear.protocol Playable: Identifiable
// DOESN'T WORK where ID: Int
{
// DOESN'T HELP associatedtype ID = Int
// DOESN'T HELP var id: Int { get }
func play()
}
struct Music: Playable {
var id: Int
func play() { print("playing music #\(id)") }
}
(Music(id: 1)).play() // displays: "playing music #1\n"
class Game: Playable {
var id: Int
init(id: Int) {
self.id = id
}
func play() { print("playing game #\(id)") }
}
(Game(id: 2)).play() // displays: "playing game #2\n"
enum Lottery: Int, Playable {
case state = 100
case church
case charity
var id: Int {
return self.rawValue
}
func play() { print("playing lottery \(self) #\(self.rawValue)") }
}
Lottery.church.play() // displays: "playing lottery church #101\n"
var stuff: [Playable] = [] // error: Protocol 'Playable' can only be used as a generic constraint because it has Self or associated type requirements
stuff.append(Music(id: 10))
stuff.append(Game(id: 24))
stuff.append(Lottery.charity)
stuff.map { $0.id }My goal is to have different structs and classes conforming to Playable (and hence to Identifiable) able to live inside a Collection.
If a file is moved to the Trash then a class implementing FilePresenter will have presentedSubitem(at:didMoveTo:) called. The didMoveTo string seems to follow this pattern:
file:///Users/<USER>/.Trash/<FILENAME>
Of course I can examine the path and look for a component .Trash, but this feels unreliable. Is there a better way?
I have a master-detail app with a Picker control in the detail for editing a field. After picking the form cell for the picker is gray. This only happens when I use StackNavigationViewStyle: remove that and the cell reverts to normal white.
Is is a bug or my mistake? I am using Xcode 12.1, targeting iOS 14.0, building on macOS 10.15.7.
Here's some sample code.
ContentView is:
@State private var boys = ["Arthur", "Cedric"]
var body: some View {
NavigationView {
List {
ForEach(boys, id: \.self) { boy in
NavigationLink(
destination: EditBoyView(boy: boy),
label: {
Text(boy)
})
}
}
.navigationBarTitle("Boys")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
and the EditBoyView is:
public var boy: String
@State private var name: String = ""
static var boyNames = ["Arthur", "Bill", "Cedric", "Dean"]
var body: some View {
Form {
Picker("Name", selection: $name) {
ForEach(Self.boyNames, id: \.self) { choice in
Text(choice)
}
}
}
.navigationBarTitle(boy, displayMode: .inline)
.onAppear {
if name == "" { name = boy }
}
}
}
If you comment out line 15 of the ContentView then the picker cell is white.
I read the vague guidance in the HIG (https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/custom-icons/) on making a "glyph". I've tried Pixelmator, Graphic, and Sketch to make all grayscale on transparent PNGs, SVGs, and PDFs. I still cannot make an asset that is tintable when I use it in a TabView tabItem Image.
If I use an SF Symbols image (systemName) then I get a tintable icon. The technical guidance in the HIG is too vague. What is "monochomatic" here? 1-bit color? Grayscale? "Uses a mask to define its shape" is also vague. Do they mean an alpha channel? An alpha mask?
I don't have Photoshop or Illustrator, so if someone can give me some clear technical guidance relevant to one of the tools I do have that'd be appreciated.
I made a subclass of UICollectionViewCell and Swift is complaining that I'm not allowed to use superclass properties like bounds, backgroundView or selectedBackgroundView. This very code was given by Appleʼs documentation - https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/changing_the_appearance_of_selected_and_highlighted_cells so I don't understand why it's disallowed.
I declared class MyCollectionViewCell: UICollectionViewCell method awakeFromNib.
class MyCollectionViewCell: UICollectionViewCell {
...
override class func awakeFromNib() {
...
let redView = UIView(frame: bounds)
redView.backgroundColor = colorLiteral(red: 1, green: 0, blue: 0, alpha: 1)
self.backgroundView = redView
let blueView = UIView(frame: bounds)
blueView.backgroundColor = colorLiteral(red: 0, green: 0, blue: 1, alpha: 1)
self.selectedBackgroundView = blueView
Xcode 12.2 gives an error about bounds, backgroundView, and selectedBackgroundView saying stuff like "Instance member 'bounds' cannot be used on type 'MyCollectionViewCell'".
If I declare a variable as UICollectionViewCell I can set these properties in it, but a function in a subclass of UICollectionViewCell cannot access its own properties?
I'm curious if anyone has a way to remove or move the fixed buttons on the Xcode 12 Touch Bar?
It's 2021 and 3 years ago this was the answer to a similar question. It doesn't discuss the fixed buttons for Run/Stop/Back/Next: https://developer.apple.com/forums/thread/80896?login=true
I am forever hitting the Run button by accident and want to remove it or at least shove it over so no buttons are just right of the escape key on my MBP 2019.
I want my app to receive certain data types shared from other apps. I'm interested in text and URLs today, and maybe images later. UIActivity seems to be the way to start but I don't know what to do with the subclass I've created.
I assume it at least needs to be declared in the app's properties, but I don't know where to read about that and nothing stands out in the project editor. I don't know the API or keywords to do my research, so if anyone can point me I'll appreciate it.
I am making an iPhone-first app which has a 2 level data structure. I want the user to be able to drag List rows from section to section, but not reorder the sections. Is there a SwiftUI way to do it, or should I resort to UIKit?
The basic problem seems to be that ForEach.onMove only allows reordering within its nearest datasource. That seems sensible as a general facility.
As it stands now drags can only happen within a section.
Swift
ForEach(groups) { group in
Section(header: Text(group.text)) {
ForEach(group.items) { item in
Text(item.text)
}
}
}
.onMove { … }
I might be willing to dive into UIKit to get this done, if it'll handle it. Right now I've flattened the data and marked some items as "containers" and others as "leaves". All get emitted as a dumb flat list:
Swift
ForEach(items) { item in
if item.isContainer {
Text(item.text).bold()
}
else {
Text(item.text)
}
}
.onMove { … }
The major downside is users can move the container "section header" lines.
Drag and drop doesn't seem to work on iPhone, just iPads. I'm kinda shy about hierarchical lists using List(_,children:) because I expect move would still allow top level items (my containers) would be allowed to be moved.
My app deal with a lot of domain-specific jargon. Is there a way to augment the vocabulary used in a SwiftUI TextField (or a UITextInput) so that autocorrection and spelling anticipation will suggest the jargon words first?
Augmentation of dictation support isn't necessary but would be a nice to have.
Is there a way to view the contents of an app's NSUbiquitousKeyValueStore? I was expecting to find a property or method that listed the keys, or maybe a web app like the CloudKit Dashboard.
I would like the first() operator to send a value as soon as it's received a value that satisfies the condition (and to finish publishing as well). But I don't know how to test this is really happening. The only test I've devised is below, but I suspect it is wrong. The map operator will keep demanding values of course, so I expect it to print all of them. Yet the sink subscriber doesn't invoke receiveValue or receiveCompletion until after map is done, which suggests first is awaiting upstream completion. Does first really does need the upstream to complete before it sends anything onward? What's really the story here for first?
import Foundation
import Combine
let numbers = (-10...10)
let cancellable = numbers.publisher
.map({ n in
Thread.sleep(forTimeInterval: 1)
print("sending \(n)")
return n
})
.first { $0 0 }
.sink { completion in
switch completion {
case .failure(_): print("failed")
case .finished: print("finished")
}
} receiveValue: { print("\($0)") }
My specific situation is I'm monitoring for when the network becomes available the first time. Of course the monitoring source will never (should never) finish but I do want completion for a pipeline subscribing to that monitor with first.
I've made an "action extension" and now I need to make a glyph or template for NSExtensionServiceFinderPreviewIconName. The documentation has been useless for me.
Everything I do ends up with a generic black image overlaid with some faint template lines:
I understand a glyph ≠ template ≠ icon, but that glyph and template are both acceptable for the action extension. I've tried various ways to make my monochrome, black-and-transparent image but I'm missing something. I started with making it in Sketch. The PNG export has alpha and is black and white, though the color mode of the file is probably full color. I ran it through Icon Set Studio but Xcode warned me there were problems with it, and it came out entirely black.
I took that PNG into Pixelmator Pro and used it to make a clipping mask since one of the hallmarks of a glyph is also supposed to be an alpha mask. Re-exported this new PNG with no change or improvement. Exported it as an SVG, but still nothing helping.
The docs don't say where the image needs to be in the Xcode workspace. I've tried putting it in both the containing app's Asseets.xcassets and in the extension's Media.xcassets, but neither helps.
Once I downloaded a glyph template file (for Sketch) from Apple, but it is tremendously complicated and I hope I can get away without making a version for every font weight and size class.
A step by step guide would help a lot, so if anyone has some energy to make one I bet other indies would appreciate it. We can't all afford $$$ for a graphic artist.
Using CloudKit, when I perform CKFetchDatabaseChangesOperation(previousServerChangeToken:) the response in fetchDatabaseChangesCompletionBlock is an error:
Metasync Continuation could not properly be parsed
The first time through this works when the token is nil. The second time through it fails with this error. It was working at one time.
I've tried deleting the app and resetting the development database as well.
I am guessing this has to do with the server change token. I save and restore the server change token to UserDefaults using NSKeyedArchiver to archive/unachive it as Data, so it should be perfectly preserved. I'm using the privateCloudDatabase with a non-default zone.