在故事板中,我使用各种格式选项布局一组标签.
然后我做:
label.text = @"Set programmatically";
Run Code Online (Sandbox Code Playgroud)
并且所有格式都丢失了!这在iOS5中运行良好.
必须有一种方法只更新文本字符串而不重新编码所有格式?!
label.attributedText.string
Run Code Online (Sandbox Code Playgroud)
是只读的.
提前致谢.
从 SwiftUI 视图推送到 UIKit 时,导航栏项目不存在或未添加。
\n我在故事板中添加了一项,在代码中添加了一项,但都没有显示。
\n这可能是 SwiftUI 中的一个错误,但我觉得这可能是一个很常见的情况,也许我遗漏了一些东西?
\n与这个问题有一些重叠:Navigation Bar Items after Push from SwiftUI to UIKit尽管我不确定它们是否相同
\nclass MyHostingController: UIHostingController<SwiftUIView> {\n \n required init?(coder aDecoder: NSCoder) { \n super.init(coder: aDecoder, rootView: SwiftUIView())\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\nstruct SwiftUIView: View {\n var body: some View {\n NavigationLink(\n destination: MyUIKitView(),\n label: {\n Text("Go to MyUIKitView")\n })\n }\n}\n
Run Code Online (Sandbox Code Playgroud)\n3和4之间粘上胶水
\nstruct MyUIKitView: UIViewControllerRepresentable {\n …
Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller uibarbuttonitem swiftui
我有一个应用程序,其主要目的是将数据输入HealthKit.我想写一些Xcode UI测试来验证它是否成功编写了这些数据,但是我在Health应用程序中验证数据时遇到了一些困难.
当我最初录制我的测试时,它跳过我的模拟主页按钮按下,但它正在录制,当我滑到第一个主屏幕并导航到Health应用程序以显示数据点.
我搜索了如何按Home键,发现这个(有效):
XCUIDevice.shared.press(.home)
Run Code Online (Sandbox Code Playgroud)
但是,它记录的其他调用实际上都不适用于应用程序之外的导航.在主屏幕上滑动的录制代码显然看起来不对,当我tap()
用a swipeRight()
或者替换时也不起作用swipeLeft()
:
app.childrenMatchingType(.Window).elementBoundByIndex(1).childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other).element.childrenMatchingType(.Other).element.childrenMatchingType(.Other).elementBoundByIndex(0).childrenMatchingType(.ScrollView).element.tap()
Run Code Online (Sandbox Code Playgroud)
接下来几行,用于在主屏幕上启动应用程序,甚至不适用于当前可见页面上的应用程序图标:
let elementsQuery = app.scrollViews.otherElements
elementsQuery.icons["Health"].tap()
Run Code Online (Sandbox Code Playgroud)
有没有办法实现我正在尝试做的事情,或者我需要等待验证端到端测试,直到我添加从HealthKit读取到我的应用程序的能力?
我已经构建了一个Apple Watch App,它使用CLLocation来跟踪用户位置.应用程序的想法是使用内置GPS工作,而不需要手机.
当我运行手表应用程序时,它会提示我提供必须从手机应用程序授予的各种权限.
如果我这样做,然后开始跟踪手表,我会初次调用
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
这很正常,我只是再次开始追踪.然后我接到一些电话
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations
但随后它就停止接收更新.
如果我在iPhone上运行完整曲目,然后在Watch上运行曲目,则跟踪工作正常.
测试完成:
我认为这很可能是一个苹果虫,但我希望有人可以某种方式指出我可能错过的方向.
我有一个在模拟器和设备上构建和运行良好的项目,但在归档时失败.
该项目非常陈旧,但我创建了一个单独的组件,我在工作区中添加了该组件.
主要项目是用Objective-C编写的,新项目是用Swift 4编写的.该项目还使用CocoaPods,还包括用Swift 3.2编写的另一个子项目.
有各种错误都归结为同一件事,子项目在编译时没有产生任何输出.或者它只是没有编译.我发现代码本身没有错误,只是在尝试引用它时:
//1
error: /Users/<user>/Library/Developer/Xcode/DerivedData/<id>/Build/Intermediates.noindex/ArchiveIntermediates/<app name>/BuildProductsPath/Release-iphoneos/Framework.framework: No such file or directory`
//2
Signing Identity: "iPhone Developer: <redacted>“
/Users/<user>/Library/Developer/Xcode/DerivedData/<id>/Build/Intermediates.noindex/ ArchiveIntermediates/<app name>/InstallationBuildProductsLocation/Applications/<app name>/Frameworks/<framework>.framework: No such file or directory
Command /usr/bin/codesign failed with exit code 1
//3
@import ModuleName;
Module ‘ModuleName’ not found
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
$(SRCROOT)
到主目标>构建设置>框架搜索路径>发布Skip install
设置YES
在子项目构建设置pod update
Always Embed Standard Swift Libraries
无论如何都没有区别其他说明:
/Users/<user>/Library/Developer/Xcode/DerivedData/<id>/Build/ Intermediates.noindex/ArchiveIntermediates/<app name>/ InstallationBuildProductsLocation/Applications/<app name>.app/Frameworks/
其他子项目和所有pod中都有一个.framework文件,但不适用于此我正在为健康应用程序开发图形实现,用户可以选择要绘制的字段.
有些字段组合从未出现在图表上.
从我到目前为止所做的调试,我可以看到所有字段的值都是正确创建的.
所以最终我的问题是,为什么"重量移动平均线"没有线
但我真的想知道如何调试这个问题.什么是建议的下一步到底?
码:
if (isMovingAverage) {
dataset.mode = LineChartModeCubicBezier;
dataset.cubicIntensity = 0.1;
dataset.lineWidth = 2;
dataset.highlightEnabled = NO;
[dataset setColor: baseColor];
dataset.fillAlpha = 1.f;
dataset.drawCirclesEnabled = NO;
NSArray *gradientColors = @[
(id)[UIColor whiteColor].CGColor,
(id)baseColor.CGColor
];
CGGradientRef gradient = CGGradientCreateWithColors(nil, (CFArrayRef)gradientColors, nil);
dataset.fillAlpha = 1.f;
dataset.fill = [ChartFill fillWithLinearGradient:gradient angle:90.f];
dataset.drawFilledEnabled = YES;
dataset.drawHorizontalHighlightIndicatorEnabled = NO;
CGGradientRelease(gradient);
NSLog(@"Dataset: %@", dataset);
}
Run Code Online (Sandbox Code Playgroud)
调试输出:
Formatting: Weight Moving Avg
2017-07-28 17:06:49.425518+0100 BodyTrackItLite[5239:1893083] Using color: UIExtendedSRGBColorSpace 0.07 0.62 0.64 1
2017-07-28 17:06:49.426723+0100 …
Run Code Online (Sandbox Code Playgroud) 我正在使用HKLiveWorkoutBuilder
&HKWorkoutRouteBuilder
跟踪Apple Watch上的锻炼.
打电话时:
[workoutBuilder finishWorkoutWithCompletion:^(HKWorkout * _Nullable workout, NSError * _Nullable error) {
}];
Run Code Online (Sandbox Code Playgroud)
返回的workout
对象不包括用户行进的距离:
(lldb) po workout.totalDistance
nil
Run Code Online (Sandbox Code Playgroud)
但是路线保存正确.
鉴于这.totalDistance
是只读的,我应该如何在watchOS 5中设置锻炼的距离?
我在尝试在真实设备上运行项目时看到以下错误,在模拟器中运行正常.
error: WatchKit App doesn't contain any WatchKit Extensions. Verify that the value of NSExtensionPointIdentifier in your WatchKit Extension's Info.plist is set to com.apple.watchkit
< app id >
< app id >.watchkit
WKCompanionAppBundleIdentifier
:< app id >
< app id >.watchkit.extension
NSExtension
> NSExtensionAttributes
> WKAppBundleIdentifier
:< app id >.watchkit
NSExtension
> NSExtensionPointIdentifier
:com.apple.watchkit
WKWatchKitApp
YES
在Watch …我有一个可在 iOS 12 上使用的应用程序。过去我使用过出色的 CocoaLumberjack,但我想转向本机Logger
类。
我很高兴不收集旧版 iOS 版本的日志,但我希望该应用程序能够在那里运行。
有没有什么好办法可以避免#available
到处打电话呢?一般来说我喜欢#available
,但对于日志来说它很笨拙
if #available(iOS 14.0, *) {
logger.info("Setting person from \(self.person, privacy: .public) to \(newValue, privacy: .public)")
}
Run Code Online (Sandbox Code Playgroud)
如果我包装该类Logger
,则无法编译它,因为日志系统有编译时间限制:
import os
public class Logger {
@available(iOS 14.0, *)
static let logger = os.Logger(subsystem: "com.progress", category: "ProgressKit")
public static func debug(_ input: String) {
if #available(iOS 14.0, *) {
logger.debug(OSLogMessage(stringLiteral: input)) // Fails: Argument must be a string interpolation
} else {
print(input)
}
}
} …
Run Code Online (Sandbox Code Playgroud) 我想AccessoryWidgetBackground()
向accessoryRectangular
小部件系列添加完整尺寸。
我创建了一个全新的项目并添加了一个全新的小部件。然后我将视图更改为:
struct Some_WidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
AccessoryWidgetBackground()
.frame(width: .infinity, height: .infinity)
.ignoresSafeArea()
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在背景模糊的情况下占据整个视图?