昨天我阅读了问题Algorithm to create costum Template/Code from String。因为这个问题没有很好地表达出来,所以它立刻就被否决了。然而,我认为这个问题本身并没有那么糟糕,所以我决定再次提出这个问题的更好版本。
好的,我想知道新 Spotify 代码的字符串加密是如何工作的。见下图:

我对在 javascript 中实现这种模式加密的可能性的程度非常感兴趣。
Spotify 代码 -我已经在上面提到过-排列成一行,分为不同大小的条。
因此,假设有一行被分为 24 个条形,并且所有条形的大小都可以是“3”、“5”、“7”或“9”。
string = 'hello' --> pattern = '3,3,5,7,9,3,7,9,9,3,3,5,3,9,5,3,3,7,5,9,3,9,3,9'
Run Code Online (Sandbox Code Playgroud)
什么是将字符串(比如 5 个字符)转换为独特模式的好方法/简单方法,然后也可以转换回来并作为字符串读取?
这是我迄今为止开发的代码,但在此代码中,我使用了一个包含 10 种不同可能性(--> 条大小)的键数组,但我只喜欢我们 4 种不同的大小。
解释:
我将我的字符串 'hello' 转换为二进制格式,并将该字符串分成最多 3 个的组以获得如下内容:['001', '110', '0']。
之后我使用上面的结果数组并在下面的键数组中找到匹配项并获取索引(10 种不同的索引 --> 10 种不同的可能性)并将它们用作条形大小。
但是,必须有一种更有效的方法将字符串转换为独特的模式。我希望有人可以帮助我改进我的小算法。预先感谢一百万。
string = 'hello' --> pattern = '3,3,5,7,9,3,7,9,9,3,3,5,3,9,5,3,3,7,5,9,3,9,3,9'
Run Code Online (Sandbox Code Playgroud)
我想在div的角落绘制某种三角形。因为我不想使用“ px”,所以我也希望使用百分比值获得相同的结果。
它应该是这样的:
.container {
position: absolute;
top: 5%;
left: 5%;
width: 60%;
height: 30%;
background: black;
color: white;
border-radius: 12px;
overflow: hidden;
}
.triangle {
position: relative;
top: 10%;
left: 90%;
width: 10%;
height: 10%;
-webkit-transform: rotate(45deg);
background: green;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="triangle"></div>
</div>Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。提前致谢!!
我声明了一个具有 4 个属性(informationA、informationB、informationC、informationD)的结构。
我还声明了一个这样的数组(该数组包含 my_struct 属性的一些名称"strings":
let keys = ["informationA", "informationB", "informationC"]
Run Code Online (Sandbox Code Playgroud)
现在我想一个for循环要经过"keys"-array和print out the struct property values当前字符串(“资料a”,“informationB”,“informationC”)。
struct my_struct {
var informationA = "test"
var informationB = "test...test"
var informationC = "test...test"
var informationD = "test...test..."
}
func getInformation() {
let keys = ["informationA", "informationB", "informationC"]
for i in keys {
print(my_struct.i) // ERROR: Type 'my_struct' has no member 'i'
// should print ---> "test", "test...test", "test...test"
}
} …Run Code Online (Sandbox Code Playgroud) 我尝试使用CoreLocation和Swift来跟踪用户的位置:(
下面你可以找到可能的ViewController.swift文件的代码.)
但是代码似乎没有像我预期的那样工作,因为我每次启动应用程序时仍然会得到相同的错误:
我确定这就是为什么我无法从locationManager()打印出当前位置的函数中得到结果的问题.
它说 "Cannot assign value of type 'ViewController' to type 'CLLocationManagerDelegate?'"
import UIKit
import CoreLocation
class ViewController: UIViewController, WKUIDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if CLLocationManager.locationServicesEnabled() {
print("CLLocationManager is available")
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
locationManager.delegate = self
locationManager.startUpdatingLocation()
}
}
let locationManager = CLLocationManager()
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
print(location.coordinate)
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在有人如何解决这个问题? - 非常感谢任何帮助,感谢提前一百万.