Post

Replies

Boosts

Views

Activity

Reduce/replace loops in my conditional checks ? [CoreData]
I am looking to integrate my code with CoreData. Presently I have the following of which allows a worker to check their requirements against an advert e.g. if the worker needs x3 sponges to clean a bathroom, then the advert must provide those sponges, but the worker can only work on set days: var cdExample: [CleaningRota] = [bathroomMonday, kitchenFriday]&#9;// [Full sample code](https://developer.apple.com/forums/content/attachment/648c2166-46f3-44a3-bfc7-5e36f3d38721){: .log-attachment} CORE DATA EXAMPLE &#9;&#9;let personAvailable: [Person] = [kath, mavis] &#9;&#9;//CORE DATA EXAMPLE : WORK ON OFFER &#9;&#9;for work in cdExample { &#9;&#9;&#9;&#9;//WORK TOOLS PROVIDED ON SITE &#9;&#9;&#9;&#9;for toolsAvailable in work.tool { &#9;&#9;&#9;&#9;&#9;&#9;//PERSONS AVAILABLE TO WORK &#9;&#9;&#9;&#9;&#9;&#9;for person in personAvailable { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//PERSONAL REQUEST : SPECIFIC WORK DAY &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if person.avilability == work.day { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//CHECK PERSON TOOL REQUIREMENTS FOR JOB &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;for personRequirement in person.materialsNeeded { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//CYCLE THROUGH TOOLS WORKER NEEDS ON SITE &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if personRequirement.tool == toolsAvailable.name { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//CONFIRM TOOLS WORKER NEEDS ARE FULLY PROVIDED &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//AVOID CHECKING SAME STOCK TWICE IF CONDITION PREVIOUSLY MET &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;if personRequirement.quantity <= toolsAvailable.stock && personRequirement.met == false { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(">>0> \(person.name)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(">>1> \(personRequirement.tool) : \(personRequirement.quantity)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print(">>2> \(toolsAvailable.name) : \(toolsAvailable.stock)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;personRequirement.met = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;person.materialID.append(toolsAvailable.id) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} As the adverts and requirements pile up this kind of system will not scale very quickly. I would like to know if there is a better way to model this data, or to check conditions. I plan to pull the cdExample from CoreData, and am unfamiliar with using it. Being a proprietary Apple Framework I do not know if anyone will help me here, but if not then how best to achieve what I want without a pyramid of doom (which I don't mind), is there a better way please? I also need to remove the stock, which I ran into trouble with as I had too many loops and hit a bug in Xcode, so I think I'm doing something wrong with all of these loops ?
1
0
728
Jan ’21
Structuring Core Data
Using a relationship I am able to pair entries together, but cannot figure out how to exactly match the customer that I am looking for, nor to create new records without overwriting the old ones. let userEntryRecord = NSEntityDescription.entity(forEntityName: “Record”, in: managedContext)! let userEntryCustomer = NSEntityDescription.entity(forEntityName: “Customer”, in: managedContext)! let dataRecord = NSManagedObject(entity: userEntryRecord, insertInto: managedContext) as? Record let dataCustomer = NSManagedObject(entity: userEntryCustomer, insertInto: managedContext) as? Customer dataRecord?.year = “2021” dataRecord?.month = “March” dataRecord?.addToCustomer(dataCustomer ?? Customer()) dataCustomer?.age = 20 dataCustomer?.gender = “male” dataCustomer?.country = “UK I would like to search for all records for October 2023, with those of ages between 20-40, how do I create a fetch request for that ? On top of that, I need to amend records, and of course create new years to attach records to, something I am having difficulty with.
2
0
632
Mar ’21
Pixelate transition in SpriteKit using CIFilter
Working from Apple documentation I wanted to apply the CIPixellate filter to a SpriteKit Node and found that SKEffectNode grants access to CoreGraphic's filters and could be a good bridge. I can get the image to pixelate, but I am looking for a smooth transition between the two stages and believe that I am having trouble with the "simd_smoothstep" function: let pixelateNode: SKEffectNode = SKEffectNode() let testSprite = SKSpriteNode(imageNamed: "testSprite") let filter = CIFilter(name: "CIPixellate")! let inputScale = simd_smoothstep(1, 0, abs(0.9)) let filter = CIFilter(name:"CIPixellate", parameters: [kCIInputImageKey: testSprite, kCIInputScaleKey: inputScale]) pixelateNode.filter = filter pixelateNode.shouldEnableEffects = true addChild(pixelateNode) pixelateNode.addChild(testSprite) ref: https://developer.apple.com/documentation/coreimage/customizing_image_transitions
1
0
613
Jul ’21
Pixelate transition in SpriteKit using CIFilter
Working from Apple documentation I wanted to apply the CIPixellate filter to a SpriteKit Node and found that SKEffectNode grants access to CoreGraphic's filters and could be a good bridge. I can get the image to pixelate, but I am looking for a smooth transition between the two stages and believe that I am having trouble with the "simd_smoothstep" function: let pixelateNode: SKEffectNode = SKEffectNode() let testSprite = SKSpriteNode(imageNamed: "testSprite") let filter = CIFilter(name: "CIPixellate")! let inputScale = simd_smoothstep(1, 0, abs(0.9)) let filter = CIFilter(name:"CIPixellate", parameters: [kCIInputImageKey: testSprite, kCIInputScaleKey: inputScale]) pixelateNode.filter = filter pixelateNode.shouldEnableEffects = true addChild(pixelateNode) pixelateNode.addChild(testSprite) ref: https://developer.apple.com/documentation/coreimage/customizing_image_transitions ref: https://developer.apple.com/documentation/coreimage/customizing_image_transitions nb. this is a repost in the SpriteKit forum. The old post can be removed: https://developer.apple.com/forums/thread/684687
1
0
719
Jul ’21
QR Code Generator (CIFilter) colours for light/dark mode ?
Using the CIFilter.qrCodeGenerator() to create a QR code I wanted to change the colours dynamically to suit Light/Dark mode, but was unable to figure out how to achieve this, is it possible please ? struct QrCodeImage {     let context = CIContext()     func generateQRCode(from text: String) -> UIImage {         var qrImage = UIImage(systemName: "xmark.circle") ?? UIImage()         let data = Data(text.utf8)         let filter = CIFilter.qrCodeGenerator()         filter.setValue(data, forKey: "inputMessage")         let transform = CGAffineTransform(scaleX: 2, y: 2)         if let outputImage = filter.outputImage?.transformed(by: transform) {             if let image = context.createCGImage(                 outputImage,                 from: outputImage.extent) {                 qrImage = UIImage(cgImage: image)             }         }         return qrImage     } } Further, I cannot see an option for the different modes and assume that any colour could be used, which would be a lot better for me. ref: https://developer.apple.com/documentation/coreimage/ciqrcodegenerator
2
0
2.0k
Feb ’22
Safari Extension : download image on click event (document.addEventListener)
I am trying to design a Safari extension to register a mouse-click on a webpage's image to automatically download that image when clicked on (whilst holding down the Command key). function handleImageClick(event) { if (event.target.tagName === 'IMG') { const imageUrl = event.target.src; const link = document.createElement('a'); link.href = imageUrl; link.download = 'image'; link.click(); } } document.addEventListener('click', handleImageClick); However, I am having no luck and wonder if it's because all functionality is limited to the toolbar popover ?
0
0
244
Nov ’23
Safari toolbar icon colour ?
I checked the official documentation but I could not see a specific colour to use for the icons sitting in Safari's toolbar (e.g. "toolbar-icon-72"). I have tried a number of different greys and although I have the one that looks good to my eye, it may be a little off to others. So I was wondering if there was a recommended colour ? I also tried using the bundled Digital Colour Meter in macOS to determine a single grey colour, but of course, at the pixel level, anti-aliasing leaves that very much down to interpretation. I have gone with 141/141/141 (RGB).
0
1
295
Nov ’23