Post

Replies

Boosts

Views

Activity

Xcode stuck in VCS diff mode
Version 14.0 beta 2 (14A5229c) Whenever I type Xcode mirrors the line I just typed showing me that this version has been updated. This is really unexpected behavior as I am not trying to review my changes or do anything git related. I got into this weird state after making a commit and pushing to my repo, making a pull request and then git pull on my local main. Xcode then mistakenly thought that all files were behind by a commit(s) as previously changed files had the downward arrow next to them. This is a bit annoying than I would like because this is affecting other things. I cannot view anything in my assets.xcassets, which also weirdly seems to be affected by this VCS bug(?). I tried turning off VCS altogether which fixes the Xcode mirroring problem, but I still can't view anything in assets. I also tried refreshing the file status which ultimately returns me back to the same state. Any suggestions?
1
0
935
Jul ’22
Showing text in a ForEach
I would like to show paragraphs of text in a ForEach. This was my latest attempt: struct ContentView: View { let bodyText = "This is a sample body text that will wrap naturally within the bounds of the container." var body: some View { WordWrapView(words: identifyWords(words: bodyText)) .padding() } func identifyWords(words: String) -> [IdentifiedWord] { let wordsArray = words.split(separator: " ").map { String($0) } var idCounter = 1 return wordsArray.reversed().map { word in let identifiedWord = IdentifiedWord(id: String(idCounter), word: word) idCounter += 1 return identifiedWord } } } struct IdentifiedWord: Identifiable { let id: String let word: String } struct WordWrapView: View { let words: [IdentifiedWord] var body: some View { GeometryReader { geometry in self.createWrappedWords(in: geometry.size) } } func createWrappedWords(in size: CGSize) -> some View { var width: CGFloat = 0 var height: CGFloat = 0 return ZStack(alignment: .topLeading) { ForEach(words) { word in self.wordView(for: word.word) .alignmentGuide(.leading, computeValue: { d in if (abs(width - d.width) > size.width) { width = 0 height -= d.height } let result = width if word == self.words.last! { width = 0 // last item } else { width -= d.width } return result }) .alignmentGuide(.top, computeValue: { _ in let result = height if word == self.words.last! { height = 0 // last item } return result }) } } } func wordView(for text: String) -> some View { Text(text) .padding([.horizontal], 4) .padding([.vertical], 2) .background(Color.gray.opacity(0.2)) .cornerRadius(4) } } The problem is that some words are overlapping other words. Am I on the right track here? I reversed the array because I'm showing arabic words, and the ForEach is placing the words in reverse order...
1
0
305
Jun ’24
how to include secrets file
Hi. My app hits an API. I have the API key stored in a config.plist file. Of course, I don't want to include this file in version control. So I omitted it. I have a workflow that when I push to my main branch, it pushes the newest version to internal testers on test flight. The problem is, the deployed code cannot find the config file, which makes sense. My approach to this problem has been to use resource tags Targets > Resource Tags And I declared that this app should download this resource. I can't figure out how to categorize it as other than download on demand . I would like it to be downloaded immediately with the app. Am I even on the right track here?
1
0
505
Jun ’24
@Attribute(.unique) working as intended, kind of
I have a model that has a unique property, e.g.: @Model final class UserWord @Attribute(.unique) let word: String let partOfSpeech: PartOfSpeech let metaData: ... At the end of the init I have this: init(...) { if partOfSpeech == .verb { metaData = fetchMeta() } } This works fine when a word is newly created and saved. But let's say there's a unique conflict and a user tries to save a new entry with the same word. Apparently this init still fires and fetchMeta edits the existing entry which gives me the error: CoreData: error: Mutating a managed object 0xb890d8167c911ade <x-coredata://4C75194F-D923-477F-BB22-ACBDECCD7530/UserWord/p2> (0x600002170af0) after it has been removed from its context. I think the solution here is to do some manual checking of the modelContext before saving. Would love to hear other's thoughts.
0
0
283
Jun ’24