How can I can the localized string for the month, day, week units. I'm not speaking about "january", "february"... But the localized word "Month". Is the only solution is to do this by hand with NSLocalizedString?
Post
Replies
Boosts
Views
Activity
I'm made an very basic iOS Widget Extension with (on iOS 16):
struct TotoView: View
var body: some View {
VStack {
Text("Toto")
.font(.headline)
}
}
}
On the SwiftUI Canvas preview, I can see the "Toto" text.
BUT when I select the Widget Target and run in the simulator, I only have the placeholder in place of text. Any idea of why?
When exporting localization in xCode for a shared framework, the localization build fails with the error "Could not choose a single platform from the supported platforms iphoneos, iphonesimulator, watchos, watchsimulator of target"
Note that the shared target has multiple supported destinations = iPhone/iPad/Apple Watch.
Running my UI Test in xCode 11.x (tried all) I have sometime "Failed to synthesize event: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: TextField, placeholderValue: 'Your Email', value: "And the tet was working because and does not always occurs. But the fact is all my UI tests and screenshots workflow is broken.Does anyone has some issue around UI testing since 11.x ?
The following code just does not behaves the same way previous to iOS 16 and with iOS 16. The blur effect does not seem to work correctly in iOS 16.
class GameScene: SKScene {
override func didMove(to view: SKView) {
let shapeNode = SKShapeNode(circleOfRadius: 30)
shapeNode.fillColor = .green
shapeNode.strokeColor = .clear
addChild(shapeNode)
let blurredShapeNode = SKShapeNode(circleOfRadius: 30)
blurredShapeNode.fillColor = .red
blurredShapeNode.strokeColor = .clear
let effectNode = SKEffectNode()
addChild(effectNode)
effectNode.addChild(blurredShapeNode)
let blurAngle = NSNumber(value: 0)
effectNode.filter = CIFilter(
name: "CIMotionBlur", parameters: [kCIInputRadiusKey: 30, kCIInputAngleKey: blurAngle])
}
}
I have a project of an iOS app with an embedded framework called TotoKit with some model classes.
Now I've added a new target with the template "WatchApp for iOS App" to my project. When I try to do "import TotoKit" from the newly created WatchKit extension, no such module is found. What do I have to do ?
I have tried without success to:
add one dependencies to TotoKi in BuildPhase of the extension target
add AppleWatch in Deployment/Target Device Families of the TotoKit target
Thanks,
Is is possible to change the home indicator color on an iPhone X? I mean the horizontal bar that suggest to slide from bottom to top to access the home screen.
The Apple documentation says that .compact style of a UIDatePicker is available from iOS 13.4.
When I launch in the simulator in iOS 13.7 my app with deployment target to iOS 13.4 and use a UIDatePicker it is displayed a the classic wheel. That does not sound normal according to documentation! Any idea?
First I prepare a long-run query to get new workouts:self.exportQuery = HKObserverQuery(sampleType: sampleType, predicate: nil, updateHandler: { query, completionHandler, error in
self.queryWorkoutsToExport() {
completionHandler()
}
})
self.healthStore.execute(self.exportQuery!)I enable the HealthStore background delivery with:self.healthStore.enableBackgroundDelivery(for: HKObjectType.workoutType(), frequency: .immediate, withCompletion: nil)Now I go outside for an outdoor running workout (with GPS trace). One my workout finished, the update handler of HKObserverQuery is called and I do a query to access the new workout:let anchoredQuery = HKAnchoredObjectQuery(type: HKObjectType.workoutType(), predicate: predicate, anchor: anchor, limit: HKObjectQueryNoLimit) { [unowned self] query, newSamples, deletedSamples, newAnchor, error inTHE PROBLEM is that the workout is correctly returned in newSamples BUT I don't have any GPS data. The resultHandler in empty. let workoutRoutesQuery = HKSampleQuery(sampleType: HKSeriesType.workoutRoute(),
predicate: HKQuery.predicateForObjects(from: workout),
limit: HKObjectQueryNoLimit,
sortDescriptors: [sort],
resultsHandler: { (query, samples, error) inAnything wrong with my process? May be .immediate is to immediate in enableBackgroundDelivery is a bit too fast and I should move to .hourly. Because when I run the same code a bit later, I have the route date.
I don't know how and since when, but now on the simulator, next to my SKScene I have a small text that display "Metal".
Does someone know how to disable this? It's a bit disturbing when trying to make some screenshot.
I want to get localized week day. On xCode, my app has only english language for the moment and I set the application region to "French".When I run this code :print("\(Calendar.current.locale)")
print("\(Calendar.current.shortWeekdaySymbols)")I have this output:Optional(en_FR (current))
["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]I understand "en_FR" as "en" because my only language is english, and FR is the region. But why shortWeekdaySymbols is not consistent with my FR region?
I want to display the long version of a date BUT WITHOUT the yearWith:let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .none
dateFormatter.doesRelativeDateFormatting = true
dateFormatter.locale = Calendar.current.locale
if let inPast = Calendar.current.date(byAdding: .day, value: -30, to: Date()) {
let text = dateFormatter.string(from: inPast)
}The output is "Wednesday, April 15, 2020" and I want to have "Wednesday, April 15"
I've defined a custom layer property (used by a custom subclass of UIView) that I animate with a UIView.animated (or UIView.animateKeyframes). I have some strange crashes arround the property.: -[__NSCFType doubleValue]: unrecognized selector sent to instanceNote that when used on a small sample project the animation/view never crash but crash in my main project. Any advice of what I should check? Xcode project settings seems the same. Something else in code or configuration to check?The full callstack is: 0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23e5ac34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fff23e3e90c ___forwarding___ + 1436 4 CoreFoundation 0x00007fff23e40bf8 _CF_forwarding_prep_0 + 120 5 QuartzCore 0x00007fff2b53a285 CA_setValueForKey + 557 6 QuartzCore 0x00007fff2b4f1e52 -[CABasicAnimation applyForTime:presentationObject:modelObject:] + 869 7 QuartzCore 0x00007fff2b4b4eb1 _ZN2CA5Layer13layer_at_timeEPNS_11TransactionEdbb + 1023 8 QuartzCore 0x00007fff2b4b4a84 _ZN2CA5Layer17layer_being_drawnEPNS_11TransactionEj + 132 9 QuartzCore 0x00007fff2b4b6671 _ZL16backing_callbackP9CGContextPv + 65 10 QuartzCore 0x00007fff2b379e48 CABackingStoreUpdate_ + 196 11 QuartzCore 0x00007fff2b4b66bd ___ZN2CA5Layer8display_Ev_block_invoke + 53 12 QuartzCore 0x00007fff2b4ad66e -[CALayer _display] + 2026 13 QuartzCore 0x00007fff2b4bfdca _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 520 14 QuartzCore 0x00007fff2b408c84 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324 15 QuartzCore 0x00007fff2b43c65f _ZN2CA11Transaction6commitEv + 649 16 UIKitCore 0x00007fff48bc155c _UIApplicationFlushRunLoopCATransactionIfTooLate + 104 17 UIKitCore 0x00007fff48c6e5fc __handleEventQueueInternal + 7487 18 UIKitCore 0x00007fff48c64dcb __handleHIDEventFetcherDrain + 88 19 CoreFoundation 0x00007fff23d9deb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 20 CoreFoundation 0x00007fff23d9dddc __CFRunLoopDoSource0 + 76 21 CoreFoundation 0x00007fff23d9d5b4 __CFRunLoopDoSources0 + 180 22 CoreFoundation 0x00007fff23d981ae __CFRunLoopRun + 974 23 CoreFoundation 0x00007fff23d97ac4 CFRunLoopRunSpecific + 404 24 GraphicsServices 0x00007fff38b2fc1a GSEventRunModal + 139 25 UIKitCore 0x00007fff48bc7f80 UIApplicationMain + 1605 26 Calendar2 0x000000010c33400b main + 75 27 libdyld.dylib 0x00007fff519521fd start + 1
For a CALayer custom property defined as below, the UIView.animateKeyframes() and a key defined with UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1) does NOT last the same duration as the UIView.animate.UI.animate is correct (10s in my test) but UIView.animateKeyframes is really faster (around 1s to do the job).Any ideas?class AnimatedLayer: CALayer {
@NSManaged var progress: CGFloat
// Whenever a new presentation layer is created, this function is called and makes a COPY of the object.
override init(layer: Any) {
super.init(layer: layer)
if let layer = layer as? AnimatedLayer {
progress = layer.progress
}
}
override init() {
super.init()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override class func needsDisplay(forKey key: String) -> Bool {
if isAnimationKeySupported(key) {
return true
}
return super.needsDisplay(forKey: key)
}
override func action(forKey event: String) -> CAAction? {
if AnimatedLayer.isAnimationKeySupported(event) {
let animation = currentAnimationContext(in: self) ?? CABasicAnimation(keyPath: event)
animation.keyPath = event
if let presentation = presentation() {
animation.fromValue = presentation.value(forKeyPath: event)
}
animation.toValue = nil
return animation
}
return super.action(forKey: event)
}
private class func isAnimationKeySupported(_ key: String) -> Bool {
return key == #keyPath(progress)
}
private func currentAnimationContext(in layer: CALayer) -> CABasicAnimation? {
let animation = action(forKey: #keyPath(backgroundColor)) as? CABasicAnimation
return animation?.copy() as? CABasicAnimation
}
}
I have added a custom property to a subclass of CALayer in order to animate the layer drawing. The property is correctly animated when I run a UIView.animate but NOT when running UIView.animateKeyframes. Any ideas? The full sample project is available here.This kind of animation works:UIView.animate(withDuration: self.duration, animations: {
self.transitionView.progress = 0
})And that DOES NOT works:UIView.animateKeyframes(withDuration: self.duration, delay: 0, options: .calculationModeCubic, animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1) {
self.transitionView.progress = 0
})Here is the layer definition :class AnimatedLayer: CALayer {
@NSManaged var progress: CGFloat
// Whenever a new presentation layer is created, this function is called and makes a COPY of the object.
override init(layer: Any) {
super.init(layer: layer)
if let layer = layer as? AnimatedLayer {
progress = layer.progress
}
}
override init() {
super.init()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override class func needsDisplay(forKey key: String) -> Bool {
if isAnimationKeySupported(key) {
return true
}
return super.needsDisplay(forKey: key)
}
override func action(forKey event: String) -> CAAction? {
if AnimatedLayer.isAnimationKeySupported(event) {
// Copy animation context and mutate as needed
guard let animation = currentAnimationContext(in: self)?.copy() as? CABasicAnimation else {
setNeedsDisplay()
return nil
}
animation.keyPath = event
if let presentation = presentation() {
animation.fromValue = presentation.value(forKeyPath: event)
}
animation.toValue = nil
return animation
}
return super.action(forKey: event)
}
private class func isAnimationKeySupported(_ key: String) -> Bool {
return key == #keyPath(progress)
}
private func currentAnimationContext(in layer: CALayer) -> CABasicAnimation? {
/// The UIView animation implementation is private, so to check if the view is animating and
/// get its property keys we can use the key "backgroundColor" since its been a property of
/// UIView which has been forever and returns a CABasicAnimation.
return action(forKey: #keyPath(backgroundColor)) as? CABasicAnimation
}
}Ands the view code is :class DayTransitionView: UIView {
override class var layerClass: AnyClass {
return AnimatedLayer.self
}
var progressLayer: AnimatedLayer {
return layer as! AnimatedLayer
}
@objc dynamic var progress: CGFloat {
set { progressLayer.progress = newValue }
get { return progressLayer.presentation()?.progress ?? progressLayer.progress }
}
// if not redefined draw:layer is not called !
override func draw(_ rect: CGRect) { }
override func draw(_ layer: CALayer, in ctx: CGContext) {
UIGraphicsPushContext(ctx);
// background color
let backgroundPath: CGPath = UIBezierPath(roundedRect: layer.bounds, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight] , cornerRadii: .zero).cgPath
ctx.addPath(backgroundPath)
ctx.setFillColor(UIColor.green.cgColor)
ctx.closePath()
ctx.fillPath()
// background color
let fillHeight = self.progressive(layer.bounds.origin.y, layer.bounds.origin.y + layer.bounds.size.height)
let fillRect = CGRect(x: layer.bounds.origin.x, y: layer.bounds.origin.y + layer.bounds.size.height - fillHeight, width: layer.bounds.size.width, height: fillHeight)
let fillPath: CGPath = UIBezierPath(roundedRect: fillRect, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight] , cornerRadii: .zero).cgPath
ctx.addPath(fillPath)
ctx.setFillColor(UIColor.red.cgColor)
ctx.closePath()
ctx.fillPath()
UIGraphicsPopContext();
}
func progressive(_ from: CGFloat, _ to: CGFloat) -> CGFloat {
return from + self.progress * (to - from)
}
}