Post

Replies

Boosts

Views

Activity

Split string into chunks of ranges
I'm trying to write a method to take a string and break it up into an array where each element of the array is the next 10 characters. So a string that's 32 characters long would end up with 3 array elements containing the first 30 characters, and then the 4th array element would have the last 2 characters. I was trying to use substringWithRange for this but as soon as I advance past the str.endIndex it throws an exception, and I can't figure out how to work around that. I know it's just a silly syntax thing, but I'm stuck.
2
0
3.6k
Dec ’15
Xcode won't open storyboard
When I try to re-open the storyboard I was just editing in the current production version of Xcode it says"The document Main.storyboard could not be opened. The operation couldn't be completed. (com.apple.InterfaceBuilder error -1)"What in the world do I do to fix that? I *really* don't want to go back to my last git commit for that file because there have been quite extensive changes with pretty complex autolayout settings.
7
0
7.2k
Mar ’16
How do you chain CIFilter
In Apple's documentation it says this:"This method, though convenient, is inefficient if used multiple times in succession. Achieve better performance by chaining filters without asking for the outputs of individual filters."That confuses me though because I don't know how to link them together without getting the output. For example, this is my method to apply a TiltShift filter, based on the instructions from Apple's docs. When I perform the gradient filter, I have to take the outputImage of that to pass into the next filter. What's the right way to be doing this? override public var outputImage: CIImage? { guard let inputImage = inputImage else { return nil } let clamped = inputImage.clampedToExtent() let blurredImage = clamped.applyingGaussianBlur(sigma: inputRadius) var gradientParameters = [ "inputPoint0": CIVector(x: 0, y: 0.75 * inputImage.extent.height), "inputColor0": CIColor(red: 0, green: 1, blue: 0, alpha: 1), "inputPoint1": CIVector(x: 0, y: 0.5 * inputImage.extent.height), "inputColor1": CIColor(red: 0, green: 1, blue: 0, alpha: 0) ]; guard let gradientImage = ciImage(from: "CILinearGradient", parameters: gradientParameters) else { return nil } gradientParameters["inputPoint0"] = CIVector(x: 0, y: 0.25 * inputImage.extent.height) guard let backgroundGradientImage = ciImage(from: "CILinearGradient", parameters: gradientParameters) else { return nil } let maskParameters = [ kCIInputImageKey: gradientImage, kCIInputBackgroundImageKey: backgroundGradientImage ] guard let maskImage = ciImage(from: "CIAdditionCompositing", parameters: maskParameters) else { return nil } let combinedParameters = [ kCIInputImageKey: blurredImage, kCIInputBackgroundImageKey: clamped, kCIInputMaskImageKey: maskImage ] return ciImage(from: "CIBlendWithMask", parameters: combinedParameters) } private func ciImage(from filterName: String, parameters: [String: Any]) -> CIImage? { guard let filtered = CIFilter(name: filterName, parameters: parameters) else { return nil } return filtered.outputImage }
5
1
3.4k
Feb ’19
How do you return a Publisher error?
I'm trying to wrap my head around Combine still, and so in my class that handles web requests I've written this method:static func downloadNumbersPublisher(datesByType: [LottoType: (start: Date, end: Date)]) -> URLSession.DataTaskPublisher { guard let url = downloadUrl(using: datesByType) else { return } var request = URLRequest(url: url) request.addValue("gzip", forHTTPHeaderField: "Accept-Encoding") let session = URLSession(configuration: .ephemeral) return session.dataTaskPublisher(for: request) }What I'm not clear on though is what I actually return on line 2, the guard statement.
2
1
6.4k
Jul ’19
Debug pass.json
How do I get errors from the simulator when something is wrong with the pkpass file? I have a 'good' version of my pass.json that drags into the simulator without issues. I have a different version that does nothing, so clearly something is wrong with the JSON, but I can't find what.In the simulator I've done Debug -> Open System Log but when I drag in the bad pkpass file, nothing is displayed.
2
0
2.7k
Dec ’19
Core Data entity creation fails in remote notification
I've got a simple app delegate method to create a core data object when my push notification arrives. The save() is returning nilError and I can't figure out what I'm doing wrong. I've verified all the elements of Message have expected data. The attributes are just String, Data, and Date types. class AppDelegate: NSObject, UIApplicationDelegate {  @Environment(\.managedObjectContext) private var managedObjectContext   func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {   guard let text = userInfo["text"] as? String,      let image = userInfo["image"] as? String,      let url = URL(string: image) else {    completionHandler(.noData)    return   }   let context = self.managedObjectContext   URLSession.shared.dataTask(with: url) { data, response, error in    guard let data = data, error == nil else {     completionHandler(.failed)     return    }    context.perform {     let message = Message(context: context)     message.text = text     message.image = data     message.received = Date()     do {      try context.save()      completionHandler(.newData)     } catch {      print(error)      completionHandler(.failed)     }    }   }.resume()  }
0
0
500
Oct ’20
Download file from push notification
In my didReceive(_:withContentHandler:) method I'm trying to download a file. I get the URL of the mp4 file I want to download and then do this: bestAttemptContent.body = "I'm here" do {	 	let data = try Data(contentsOf: url) } catch { 	bestAttemptContent.body = error.localizedDescription } The body isn't modified at all when I do a file download like that. If I comment out line 4, the body is updated as expected. I verified that it's not timing out because the serviceExtensionTimeWillExpire method changes the title so I know a timeout happened and that's not the case. In the debugger I verified the URL is exactly what was passed as part of the payload, and I've verified that URL is correct. If I try to step over line 4 in the debugger it just goes into assembly code and never moves on. The file only takes a few seconds to download from my mac. Both the main project and the service extension allow insecure loads from the net. Any thoughts on why it seems to abort and yet not simply move into the catch block as expected?
0
0
452
Oct ’20
Custom Actions for push not working on the simulator
When I run my app on my device and send a push notification, the custom UI shows up and the custom actions appear as well. By custom actions I med the UNNotificationAction items. If, however, I run on the simulator, that doesn't work. When I drag my payload onto the simulator the notification shows and on long-press I see the custom UI, but I don't see any of the custom buttons. Is this a known bug?
1
0
667
Nov ’20
SwiftUI know when new page from TabView is activated
In my view I've done this: var body: some View {   TabView {     DayView(summary: History.shared.today())     DayView(summary: History.shared.thisWeek())     DayView(summary: History.shared.thisMonth())   }   .tabViewStyle(PageTabViewStyle()) } how do I tell the appropriate DayView when it has become the active page? If it matters for implementation, this is specifically when using WatchOS.
1
0
775
Dec ’20
watchOS NavigationLink not hidden when isActive is false
I'm trying to have a navigation link that is triggered programatically. If I use the following code, on iOS, then the second NavigationLink is not put into the UI, as expected. On watchOS, however, there's a visible button with no text. How can I accomplish this on watchOS? var body: some View {   NavigationView {     VStack {       NavigationLink("No login required", destination: UnprotectedView())       NavigationLink(destination: ProtectedView(), isActive: $isActive) {         EmptyView()       }       Button("Login required", action: pushIfAuthenticated)     }     .navigationBarTitle("Choose")   } }
3
0
2.2k
Dec ’20
WKSnapshotRefreshBackgroundTask with SwiftUI
When my SwiftUI based watch app responds to an WKSnapshotRefreshBackgroundTask, how do I change the navigation stack? Before using SwiftUI we'd just do this: if let root = WKExtension().shared.rootInterfaceController { 		root.pushController(withName: "Controller1", context: nil) 		root.pushController(withName: "Controller2", context: nil) } And now I'd have the screen I wanted. Not sure how to accomplish that same thing with SwiftUI
0
0
604
Dec ’20
performNotificationDefaultAction with SwiftUI
In my watchOS extension, I'm using the WKUserNotificationHostingController. If I override isInteractive and return true, how do I allow for opening the app? Essentially I want to know how to make the app open when tapping on specific elements of the custom View which is displayed. In previous versions I'd just call the performNotificationDefaultAction method on the WKUserNotificationInterfaceController.
0
0
790
Mar ’21