我正在学习汇编语言,无法自己解决以下练习。
假设以下值存储在指定的内存地址和寄存器中:
现在,我们有一条指令:
addl %ecx , (%eax)
对我来说,这意味着 - 将存储在 %ecx 和内存地址 (%eax) 中的值相加的结果存储在内存地址中(%eax)。
该练习的正确答案是:值 0x100 和目标地址 0x100。
我知道正确的操作数是目标地址,但是我们如何0x100通过计算%ecx+获得值(%eax)?
我试图将选择器添加到我的UISegmentedControl.
segmentedControl = UISegmentedControl(items: items)
segmentedControl.layer.cornerRadius = 12.0
segmentedControl.layer.borderColor = UIColor.purpleLight.cgColor
segmentedControl.layer.borderWidth = 1.0
segmentedControl.layer.masksToBounds = true
segmentedControl.backgroundColor = .white
self.contentView.addSubview(segmentedControl)
segmentedControl.addTarget(self, action: Selector(("changeColor:")), for:.valueChanged)
Run Code Online (Sandbox Code Playgroud)
然后:
func changeColor(sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 1:
segmentedControl.backgroundColor = UIColor.green
case 2:
segmentedControl.backgroundColor = UIColor.blue
default:
segmentedControl.backgroundColor = UIColor.purple
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我点击它时,我收到了一个错误 - unrecognized selector sent to instance 0x7fcf5f049000
我的API有路径和后面的int.
例如, /get/news/{id}.
对于路径端点,我有这样的枚举:
enum Endpoints : String {
case news = "news"
}
Run Code Online (Sandbox Code Playgroud)
有没有方便的方法来使用相关的值?
就像是 :
case newsById(id: String) = "get/news/" + id
Run Code Online (Sandbox Code Playgroud) 我有包含单个图像视图的单元格.如何有这样的成本:左(12)顶(12)右(12)机器人(12).
它没关系,但我想要的是,保存偏移(可能摆脱底部偏移),但添加高度=宽度等约束,因此图像将始终是方形,但是,将始终具有等于的左上右偏移12.
添加height = width约束后的图像没有显示.图像是从网上下载的,因此无法立即使用.怎么解决?
我列举了一些案例:
case one(value: myClassOne)
case two(value: myClassTwo)
Run Code Online (Sandbox Code Playgroud)
我想检查该枚举的值。现在我以:
switch self.model! {
case .one:
// Great, my case here
default:
break
}
Run Code Online (Sandbox Code Playgroud)
但是我宁愿做这样的事情:
if case self.model(let value) is myClassOne { // do smth } // Not compiling
Run Code Online (Sandbox Code Playgroud)
是否有简单的方法可以简单地提取枚举值并检查其是否满足某些条件或类的相等性?
我尝试在Swift中使用reduce函数。
taken = basket.reduce(into: 0) { (initial, bi) in
initial + bi.amount() - bi.discount()
}
Run Code Online (Sandbox Code Playgroud)
但是我得到一个错误: Result of operator '-' is unused.
我正在尝试使用 php 创建乘法表,如下所示:
<?php
$cols = 10;
$rows = 10;
?>
Run Code Online (Sandbox Code Playgroud)
... 很多 html 代码 ...
<?php
echo "<table border=\"1\">";
for ($r =0; $r < $rows; $r++){
echo('<tr>');
for ($c = 0; $c < $cols; $c++)
echo( '<td>' .$c*$r.'</td></tr>');
}
echo("</table>");
?>
Run Code Online (Sandbox Code Playgroud)
我可能会错过一些东西,但无法弄清楚它是什么。
任何建议将不胜感激,谢谢!
在我的一个控制器中我使用自定义工具栏,我想在ios中获得默认工具栏(导航栏)的高度.我用过宏#define NAVBAR_HEIGHT self.navigationController.navigationBar.frame.size.height.
但是,当控制器没有嵌入导航堆栈时,宏返回零.
我不想使用44的常量,因为它可能在其他Apple设备上有所不同.
对于标签栏,我使用:
+(CGFloat)getTabBarHeight{
UITabBarController *tabBarController = [UITabBarController new];
CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;
return tabBarHeight;
}
Run Code Online (Sandbox Code Playgroud)
有没有这样的片段,所以我可以返回导航控制器工具栏的值?
我有字符串,由一个预定义的字符串+随机字母组成,如" https://www.facebook.com/ "和"userId".
我有3个预定义的社交主机字符串:
let vkPredefinedHost = "https://vk.com/"
let fbPredefinedHost = "https://www.facebook.com/"
let instPredefinedHost = "https://www.instagram.com/"
Run Code Online (Sandbox Code Playgroud)
我想要的是,提取社交ID,这是一个字符串后面跟着那个字符串(我不确切知道我得到了哪一个).
所以我的问题是:
1)如何检查字符串是否包含我预先定义的字符串之一
2)如何提取字符串后跟此字符串
例如,我得到" https://www.instagram.com/myUserId12345 ",我想得到myUserId12345
我想为与 API 交互的函数编写一个测试。我最终得到:
class FileDownloaderTests: XCTestCase {
// MARK: timeouts
let regularTimeout: TimeInterval = 10
let largeTimeout: TimeInterval = 15
func testDownload() {
// URLS.firstFileUrl.rawValue
let downloader = FileDownloader(string: URLS.firstFileUrl.rawValue)
downloader.download(successCompletion: {
XCTAssertTrue(true)
}) { error in
print("error in test - \(error)")
}
waitForExpectations(timeout: largeTimeout, handler: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
因此,它假设等待 largeTimeout(15 秒)来 successCompletion 关闭,然后测试应该通过。但最终还是报错了:
*** Assertion failure in -[FileDownloaderTests.FileDownloaderTests waitForExpectationsWithTimeout:handler:], /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-14460.20/Sources/XCTestFramework/Async/XCTestCase+AsynchronousTesting.m:28
/Users/Necrosoft/Documents/Programming/Work/Life-Pay/FileDownloader/FileDownloaderTests/FileDownloaderTests.swift:28: error: -[FileDownloaderTests.FileDownloaderTests testDownload] : failed: caught "NSInternalInconsistencyException", "API violation - call made to wait without any expectations having …Run Code Online (Sandbox Code Playgroud)