I created a data structure based on a dictionary of words. The purpose is to link each word to all other words made up of the same letters plus one.
Example: table -> ablate, cablet, tabled, gablet, albeit, albite, etc.
For this I built a data model made of three entities: Word, Draw, Link.
A Draw is a set of letters corresponding to a Word and sorted in alphabetic order, like : HOUSE -> EHOSU. A Link is a letter that you add to a Draw to get another Draw.
So my data model looks like this:
And here is how I implemented it in Xcode:
Entity Word
(let's forget the attribute optComp that plays no role here)
Entity Draw
Entity Link
I am populating the data in two steps:
first I read a list of words from a .txt source and I populate the Word entity and at the same time the Draw entity with the corresponding relationship (function loadDic())
This first step apparently works fine. I can easily find all anagrams of any word with something like word.sort.word.spelling
I read through the Draw entity. For each draw I seek all existing +1 draws considering each letter of the alphabet. If there are, I create a Link and add the relationships (function createLinks())
Here is where something goes wrong. If the Link's and the relationship Draw.plus seem to be correctly created, the other relationship Link.gives is only partially populated, say 50%.
Moreover, I tried to apply an additional routine (updateLinks()) , focusing only on Link's with an empty Link.gives relationship and updating them. But again, only 50% of the nil relationships appear to be populated.
I could not find out why those relationships are not properly populated. If someone can help me out I would be grateful.
Here is the code:
LoadDic() function (OK) :
func loadDic() {
print("Loading dictionary...")
dataAlreadyLoaded.toggle()
guard let url = Bundle.main.url(forResource: INPUT_FILE, withExtension: "txt") else {
fatalError("\(INPUT_FILE).txt not found")
}
if let dico = try? String(contentsOf: url, encoding: String.Encoding.utf8 ) {
let lines = dico.split(separator: "\r\n")
for line in lines {
let lineArray = line.split(separator: " ")
print("\(lineArray[0])") // word
let wordSorted = String(lineArray[0].sorted())
let draw = getDraw(drawLetters: wordSorted) ?? addDraw(drawLetters: wordSorted) // look if draw already exists, otherwise create new one.
let wordItem = Word(context: viewContext) // create word entry with to-one-relationship to draw
wordItem.spelling = String(lineArray[0])
wordItem.optComp = (Int(String(lineArray[1])) == 1)
wordItem.sort = draw
do {
try viewContext.save()
} catch {
print("Errort saving ods9: \(error)")
}
}
}
print("Ods Chargé")
}
func addDraw(drawLetters: String) -> Draw {
let newDraw = Draw(context: viewContext)
newDraw.draw = drawLetters
return(newDraw)
}
func getDraw(drawLetters: String) -> Draw? {
let request: NSFetchRequest<Draw> = Draw.fetchRequest()
request.entity = Draw.entity()
request.predicate = NSPredicate(format: "draw == %@", drawLetters)
do {
let drw = try viewContext.fetch(request)
return drw.isEmpty ? nil : drw[0]
} catch {
print("Erreur recherche Tirage")
return nil
}
}
createLinks() function (NOK):
func createLinks() {
var erreur = " fetch request <Draw>"
let request: NSFetchRequest<Draw> = Draw.fetchRequest()
request.entity = Draw.entity()
request.predicate = NSPredicate(value: true)
print("Building relationships...")
do {
let draws = try viewContext.fetch(request)
count = draws.count
for draw in draws {
print("\(count) - \(draw.draw!)")
linkTable.removeAll()
for letter in ALPHABET {
print(letter)
let drawLettersPlus = String((draw.draw! + String(letter)).sorted()) // draw with one more letter
if let drawPlus = draws.first(where: { $0.draw == drawLettersPlus }) { // look for Draw entity that matches augmented draw
let linkItem = Link(context: viewContext) // if found, create new link based on letter with relationship to augmented draw
linkItem.letter = String(letter)
linkItem.gives = drawPlus
erreur = " saving \(draw.draw!) + \(letter)"
try viewContext.save()
linkTable.append(linkItem) // saves link to populate the one-to-many relationship of the initial draw, once the alphabet is through
}
}
let drawUpdate = draw as NSManagedObject // populate the one-to-many relationship of the initial draw
let linkSet = Set(linkTable) as NSSet
drawUpdate.setValue(linkSet, forKey: "plus")
erreur = " saving \(draw.draw!) links plus"
try viewContext.save()
count -= 1 // next draw
}
} catch {
print("Error " + erreur)
}
print("Graph completed")
}
updateLinks function (NOK):
func updateLinks() {
var erreur = "fetch request <Link>"
let request: NSFetchRequest<Link> = Link.fetchRequest()
request.entity = Link.entity()
print("Running patch...")
do {
request.predicate = NSPredicate(format: "gives == nil")
let links = try viewContext.fetch(request)
for link in links {
let baseDraw = link.back!.draw!
print("\(baseDraw) \(link.letter!)")
let augmDrawLetters = String((baseDraw + link.letter!).sorted())
if let augmDraw = getDraw(drawLetters: augmDrawLetters) {
viewContext.perform {
let updateLink = link as NSManagedObject
updateLink.setValue(augmDraw, forKey: "gives")
erreur = " saving \(augmDraw.draw!) \(link.letter!)"
do {
try viewContext.save()
} catch {
print("Erreur mise à jour lien")
}
}
}
}
} catch {
print("Error " + erreur)
}
}
RESULT
And this is the output showing the content of the Draw entity with relationships after createLinks() is applied:
And here after updateLinks() is applied :
General
RSS for tagExplore the art and science of app design. Discuss user interface (UI) design principles, user experience (UX) best practices, and share design resources and inspiration.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi, I've been trying for an hour to turn the symbols in sf symbols from left to right to right to left, I'd appreciate some help
Hi,
When using just one model container, I have the following code:
let modelContainer: ModelContainer
init() {
do {
entriesModel = try ModelContainer(for: Model.self)
} catch {
fatalError("Could not initialize ModelContainer")
}
}
I am attempting to implement two like so:
let model1: ModelContainer
let model2: ModelContainer
init() {
do {
model1 = try ModelContainer(for: Model1.self)
model2 = try ModelContainer(for: Model2.self)
} catch {
fatalError("Could not initialize ModelContainer")
}
}
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(model1)
.modelContainer(model2)
}
}
However, when in the Views that I'd like to implement I don't know how to declare the models. I tried this:
@Environment(\.model1) private var model1
@Query private var data: [Model1]
But I get the error: Cannot infer key path type from context; consider explicitly specifying a root type
How do I implement multiple model containers in multiple different views?
I've made the code in xcode for apple watch with 2 swift view (contentView.swift and interfaceController.swift).The swift for sound and haptic feedback is in InterfaceController.swift. But the the sound does not appear with haptic feedback in apple watch after complete the xcode.
the app is done but no sound appear with haptic feedback when rotate apple watch digital crown. when crown rotated but sound appear
code
import WatchKit
import AVFoundation
import WatchKit
class InterfaceController: WKInterfaceController {
// ... your UI elements
func playSelectionHapticAndSound() {
// Play a haptic feedback pattern
WKInterfaceDevice.current().play(.success)
// Load and play a selection sound effect
guard let soundURL = Bundle.main.url(forResource: "spin", withExtension: "wav") else { return }
do {
let player = try AVAudioPlayer(contentsOf: soundURL)
player.play()
} catch {
print("Error playing sound: \(error)")
}
}
}
I have been battling the new Icon Composer app for 2 days trying to build an app icon. However, I cannot get it to import any files. I have used the Apple provided App Icon Template. I have exported my layers to .svg and when I open the finder, everything is disabled. I can't find help for this anywhere. I am on Sequoia on my Mac and not sure how to design this app icon without access to the composer.
i accidentally updated my iphone with the ios 18 and i dislike it. the emoji display were too huge and the picture gallery was kinda messy. i hope apple could fix this by bringing back the old emoji display and the gallery settings.
I am seeking guidance regarding the inclusion of app branding on the navigation controller across all screens within our application. Although it appears that Apple doesn't typically recommend this practice, our client has specifically requested the addition of branding elements.
Can you please advise if it is permissible to implement such branding, and whether doing so would affect the app review process?
The apple guideline state:
"Ensure branding always defers to content. Using screen space for an element that does nothing but display a brand asset can mean there’s less room for the content people care about. Aim to incorporate branding in refined, unobtrusive ways that don’t distract people from your experience."
Source: https://developer.apple.com/design/human-interface-guidelines/branding
I’m working on a SwiftUI sheet that has a specific size 624 x 746, but I’m running into issues on certain devices like the iPad mini in landscape or when using Stage Manager. The sheet sometimes gets cut off, and the content inside isn’t fully visible.
Current Implementation:
The sheet is 624 x 746, but if there's less width or height around the sheet, I want it to scale dynamically while maintaining the aspect ratio (to ensure the content can always be shown)
Ideally, I’d love for the sheet to increase in size on larger screens to cover more of the page behind it.
The sheet contains a NavigationStack with multiple pages.
Problems I’m Facing:
iPad mini (landscape): The bottom content (like buttons) gets cut off when the sheet height is constrained.
Stage Manager: If the user resizes the window, the sheet doesn’t adjust properly, leading to UI clipping.
Ideal behavior: I want the sheet to dynamically scale its width and height while maintaining the aspect ratio.
Questions
How can I prevent content from being cut off when using the sheet in iPad mini landscape?
Is there a better approach to handle Stage Manager resizing dynamically?
Any insights or alternative approaches would be greatly appreciated! 🚀
Also, I’m a designer, and I’m doing this to help our development team—so please bear with my code 😅
Thanks in advance! 😊
Our application was first published on December 16, 2012, at 11:42 PM, and has been available on the market for 13 years. Over the years, we have implemented hundreds of updates to enhance and refine the app.
Our recent updates are rejected for the reason "Guideline 4.3(a) - Design - Spam" warning. How can it be for a 13 years old app.
Please advice me what to do.
Thanks in advance
Is it possible to modify or mark elements in the room plan model generated by the framework?
Dear Apple Innovation Team,
I have a game-changing iPhone concept and want Apple to explore it first.
📱 iPhone 18 – The First True Portless iPhone
No ports – MagSafe 2.0 with high-speed data transfer.
Under-display Face ID & Camera – No security compromise.
Seamless OLED Display – No interruptions, just pure screen.
📂 iPhone 20 – The Perfect Foldable
Crease-free foldable design – Apple perfects what others failed to.
Optimized iOS for foldables – Smooth UI & app integration.
Apple leads the foldable market.
🚀 Why This Matters: Apple can set a new standard & dominate both innovations.
Looking forward to your response.
Best,
Saksham Sethi
I have a problem that my widgets don't display well on Apple Watch Ultra when it is in the Night Mode. I would like to be able to detect this state so that I can provide a better view for this. Thank you.
Hello,
Im new to Xcode, ive been taking some classes and watching YouTube videos as well as using AI. Im having an issue I cannot find a video on, and AI just keeps screwing up my layout and sizing.
Here is the issue, I have a Custom Made Image for my Sign In button, for my log in page on Xcode. The issue being that I can barely see the button and when I go to adjust the size the whole layout gets screwed up. My Logo Image (supposed to take up the top 50% of the screen) takes over the whole Botton of the screen and I loose my username and password Text threads and images. I guess my question is, is this an issue with the size of image ive uploaded or is this an issue with my code? I changed the size of the Image I created in Canva to 900pixles for the width and 300pixals for the height and that did absolutely nothing to my image in Xcode.
Below is the Button and Create Account section in my code that seems to be having issues. Ppppplease help me.
var body: some View {
NavigationStack(path: $navigationPath) {
ZStack {
// Background image
Image("Background1")
.resizable()
.scaledToFill()
.ignoresSafeArea()
.clipped()
// Main content
ScrollView {
VStack(spacing: 20) {
// Logo
Image("DynastyStatDropLogo")
.resizable()
.scaledToFit()
.padding(.top, -160)
.padding(.bottom, -30)
// Form elements
// Username field
ZStack {
Image("UsernameBar")
.resizable()
.aspectRatio(contentMode: .fill)
.padding()
TextField("UserName:", text: $textInput)
.padding(.horizontal, 75)
.background(Color.clear)
.foregroundColor(.red)
.focused($focus, equals: .username)
.submitLabel(.next)
.onSubmit {
focus = .password
}
}
.frame(height: 50)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.horizontal)
// Password field and Forgot Password link
VStack(spacing: 20) {
ZStack {
Image("PasswordBar")
.resizable()
.aspectRatio(contentMode: .fill)
.padding()
SecureField("Password:", text: $textInput2)
.padding(.horizontal, 75)
.background(Color.clear)
.foregroundColor(.red)
.focused($focus, equals: .password)
.submitLabel(.go)
.onSubmit {
submitForm()
}
}
.frame(height: 50)
.clipShape(RoundedRectangle(cornerRadius: 10))
.padding(.horizontal)
// Forgot Password link (right-aligned)
HStack {
Spacer()
Text("Forgot Password?")
.foregroundColor(.blue)
.onTapGesture {
navigationPath.append("passwordRecovery")
}
}
.padding(.horizontal, 90)
}
Spacer(minLength: -110)
// SignIn Button - Explicitly showing it
HStack {
Spacer()
Button {
submitForm()
} label: {
Image("signinButton")
.resizable()
.frame(width: 500, height: 400)
}
Spacer()
}
Spacer(minLength: -300)
// Create Account (centered)
HStack {
Spacer()
Text("Create Account")
.foregroundColor(.blue)
.onTapGesture {
navigationPath.append("accountCreation")
}
Spacer()
}
.padding(.bottom, -10)
}
}
}
.onAppear {
focus = .username
}
.navigationDestination(for: String.self) { destination in
switch destination {
case "dashboard":
DSDDashboard()
case "passwordRecovery":
PasswordRecoveryView()
case "accountCreation":
AccountCreationView()
default:
EmptyView()
}
}
.alert(isPresented: $showAlert) {
Alert(
title: Text("Missing Information"),
message: Text("Enter UserName and Password to continue to DSD"),
dismissButton: .default(Text("OK"))
)
}
}
}
// Function to handle form submission
func submitForm() {
focus = nil
if textInput.isEmpty || textInput2.isEmpty {
showAlert = true
} else {
print("Login with username: \(textInput), password: \(textInput2)")
navigationPath.append("dashboard")
}
}
// Enum to manage focus states
enum FormFieldFocus: Hashable {
case username, password
}
}
Bonjour,
Je me permet d'écrire un message car je rencontre un souci avec la vue canvas j'ai le message d'erreur suivant " CrashReportError: XCPreviewAgent crashed because Adjust.framework is missing" je ne sais pas trop comment identifié le problème j'utilise pod
En vous remerciant par avance
Is there a way to revert back to the old designs? The new designs in iOS 18 are so bad and hard to use. I can’t imagine anyone actively tested this for user feedback before releasing.
This is my first day with IOS 18.1.1 and so far it’s smooth. my only problem is how chaotic the photos app has become during the update. For one, i dont like how to access any of the organization it’s at the way bottom and even after customizing and reorganizing there’s no way to to move that section to the top. i also dont like how all my photos are just out on front street when the app is launched, it makes everything hard to look at and hard to find. please fix this and make browsing photos enjoyable again.
I noticed a discrepancy between the Material specifications for tvOS on the Developer page and the naming in the Design Resources (Sketch files). Which one should we consider authoritative?
https://developer.apple.com/design/human-interface-guidelines/materials
Hi everyone,
I’m new to macOS development and working on an app idea that needs a timeline-based editor interface, similar to what you see in Logic Pro or Final Cut.
The UI I want to build would have:
A horizontal beat ruler that follows BPM and shows beat positions
Several vertical tracks stacked below it (for things like events or markers)
Horizontal zooming and scrolling
A preview panel on the right side that stays in sync with the timeline
I’m currently trying this in SwiftUI, but I’m running into some limitations and wondering if AppKit would be a better fit, or maybe a hybrid of the two.
My questions:
Where should I start when building something like this?
What’s the best way to make the beat ruler and all track layers scroll together?
How should I handle zooming in/out and syncing the display to a BPM timeline?
Is there a clean way to integrate AppKit for the timeline view while keeping SwiftUI elsewhere?
Scenario is when keyboard is opened within the app being developed then switch to other app, for instance, Notes app and create a note to enable keyboard from there. While the Notes app keyboard is active switch back to the developed app the keyboard in it is dismissed. Any thoughts?Thanks
I would like to modify the content of a published LocationNode upon been clicked by the user. But unfortunately:
func hitTest(_ point: CGPoint, options: [SCNHitTestOption : Any]? = nil) -> [SCNHitTestResult]
returns an SCNNode array from which it is impossible to retrieve the original LocationNode being inserted in order to be able to modify it.
Of course the solution would be to either insert the SCNNode corresponding to the inserted LocationNode in a custom class or conversely insert the identifier of the custom object as a tag of the LocationNode, in order to solve the issue. But both options seem impossible to implement.
May anyone help me?