滿滿的愛

文章 评论 浏览 28

滿滿的愛 2025-02-17 06:57:04

Nuget软件包注册表是在Gitlab 12.8中引入的,因此版本11.1不存在

The Nuget package registry was introduced in GitLab 12.8 so it won't be present in version 11.1

如何在gitlab nuget软件包上解析404网址?

滿滿的愛 2025-02-17 06:18:41

浏览器不知道如何从未设置的颜色中更改,因此您只需要从颜色过渡即可。在这种情况下,我使用了透明:

div {
  border: transparent;
  &:hover{
    border: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);
    transition: border 1s ease;
  }
}

The browser doesn't know how to change from a colour that isn't set, so you simply need a colour to transition from. In this case I've used transparent:

div {
  border: transparent;
  &:hover{
    border: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);
    transition: border 1s ease;
  }
}

CSS边界过渡

滿滿的愛 2025-02-17 03:18:31

您应该在单独的线程

private fun getAddress(latitude: Double, longitude: Double) {
    viewModelScope.launch {
        try {
            var addresses: List<Address>
            val deferred = this.async(Dispatchers.IO) {
                addresses = geocoder!!.getFromLocation(
                    latitude,
                    longitude,
                    1
                ) // Here 1 represent max location result to returned, by documents it recommended 1 to 5

                return@async addresses
            }
            withContext(Dispatchers.Main) {
                val data = deferred.await()
                showAddress(data)
            }

        } catch (e: Exception) {
            Log.e("location", e.message!!)
        }
    }
}

检索地址上调用地理编码器

 private fun showAddress(addresses: List<Address>) {
    val address = addresses[0]
        .getAddressLine(0) // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()

    val city = addresses[0].locality
    val state = addresses[0].adminArea
    val country = addresses[0].countryName
    val postalCode = addresses[0].postalCode
    val knownName = addresses[0].featureName // Only if available else return NULL

}

You should call Geocoder on a separate thread

private fun getAddress(latitude: Double, longitude: Double) {
    viewModelScope.launch {
        try {
            var addresses: List<Address>
            val deferred = this.async(Dispatchers.IO) {
                addresses = geocoder!!.getFromLocation(
                    latitude,
                    longitude,
                    1
                ) // Here 1 represent max location result to returned, by documents it recommended 1 to 5

                return@async addresses
            }
            withContext(Dispatchers.Main) {
                val data = deferred.await()
                showAddress(data)
            }

        } catch (e: Exception) {
            Log.e("location", e.message!!)
        }
    }
}

Retrieve address:

 private fun showAddress(addresses: List<Address>) {
    val address = addresses[0]
        .getAddressLine(0) // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()

    val city = addresses[0].locality
    val state = addresses[0].adminArea
    val country = addresses[0].countryName
    val postalCode = addresses[0].postalCode
    val knownName = addresses[0].featureName // Only if available else return NULL

}

我正在使用FusedLocation提供商,即使我的手机中的Internet Services已关闭,我也不希望我的应用程序崩溃。我尝试使用尝试/捕获,没有用

滿滿的愛 2025-02-16 20:56:58

您的问题会弄乱水域,因为您正在混合运行时和编译时间逻辑,因为在您的情况下,函数参数的数量和类型取决于某物的运行时值。

现在,您会遇到两个不同的选择:可以进行这项工作(即使在C ++ 14中),但是任何未通过正确参数的呼叫站点都将在运行时无法检测到。这样做的方法是借助 std :: enable_if_t exptype() std :: dectval 。我已经为您的示例完成了此操作,并且在C ++ 14模式下为我编译了以下编译:(

#include <iostream>
#include <type_traits>
#include <stdexcept>

enum class Fruit {
Apple,
Orange,
Pear,
};

void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();

struct Processor
{
    template<typename... Ts, typename = decltype(processApple(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Apple>, Ts&&... ts)
    {
        processApple(std::forward<Ts>(ts)...);
    }

    template<typename... Ts, typename = decltype(processOrange(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Orange>, Ts&&... ts)
    {
        processOrange(std::forward<Ts>(ts)...);
    }

    template<typename... Ts, typename = decltype(processPear(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Pear>, Ts&&... ts)
    {
        processPear(std::forward<Ts>(ts)...);
    }

    [[noreturn]] static void process(...)
    {
        // While this is inserted, it should never be called in practice,
        // unless there's a programming error.
        throw std::invalid_argument("Invalid argument specified to processFruit().");
    }
};

template<typename... Args>
void processFruit(Fruit fruit_type, Args&&... args) {
    switch (fruit_type) {
    case Fruit::Apple:
        Processor::process(std::integral_constant<Fruit, Fruit::Apple>(), std::forward<Args>(args)...);
        break;
    case Fruit::Orange:
        Processor::process(std::integral_constant<Fruit, Fruit::Orange>(), std::forward<Args>(args)...);
        break;
    case Fruit::Pear:
        Processor::process(std::integral_constant<Fruit, Fruit::Pear>(), std::forward<Args>(args)...);
        break;
    default:
        break;
    }
    postProcessing();
    return;
}

void processApple(int a, int b)
{
    std::cout << "Apple: " << a << " // " << b << std::endl;
}

void processOrange(int c)
{
    std::cout << "Orange: " << c << std::endl;
}

void processPear(double d)
{
    std::cout << "Pear: " << d << std::endl;
}

void postProcessing()
{
    std::cout << "Post processing" << std::endl;
}

int main()
{
    processFruit(Fruit::Apple, 4, 8);
    processFruit(Fruit::Orange, 15);
    processFruit(Fruit::Pear, 1.234);
    // The following will only throw an exception, but not fail to compile
    //processFruit(Fruit::Pear, 1.234, 77);
    return 0;
}

struct处理器只是为了清理名称空间,它们可能是全局函数。)这里的问题是编译器无法检测到错误的呼叫,请参阅 processFruit的评论(fruat :: pear,1.234,77); 会产生例外,但编译器无法检测到它在编译时。

在我看来,这不是很明智。由于参数取决于 fruit 无论如何类型,我真的看不到当 fruit> fruit 参数仅知道时,您什至无法执行这些功能之一的调用。运行时,因为每个呼叫站点仅适用于一种类型。

而且,如果您确实知道在编译时,可以通过超载以更简单的方式来完成这一点,这也允许更好地编译时间诊断:

#include <iostream>
#include <type_traits>

enum class Fruit {
Apple,
Orange,
Pear,
};

void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Apple>, Args&&... args)
{
    processApple(std::forward<Args>(args)...);
    // or put the code of processApple directly in here
}

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Orange>, Args&&... args)
{
    processOrange(std::forward<Args>(args)...);
    // or put the code of processOrange directly in here
}

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Pear>, Args&&... args)
{
    processPear(std::forward<Args>(args)...);
    // or put the code of processPear directly in here
}

template<Fruit f, typename... Args>
void processFruit2(Args&&... args)
{
    processFruit2Helper(std::integral_constant<Fruit, f>(), std::forward<Args>(args)...);
    postProcessing();
}

void processApple(int a, int b)
{
    std::cout << "Apple: " << a << " // " << b << std::endl;
}

void processOrange(int c)
{
    std::cout << "Orange: " << c << std::endl;
}

void processPear(double d)
{
    std::cout << "Pear: " << d << std::endl;
}

void postProcessing()
{
    std::cout << "Post processing" << std::endl;
}

int main()
{
    processFruit2<Fruit::Apple>(4, 8);
    processFruit2<Fruit::Orange>(15);
    processFruit2<Fruit::Pear>(1.234);

    // The following will fail to compile here (which is good)
    //processFruit2<Fruit::Pear>(1.234, 77);
    return 0;
}

这都说,我怀疑您的代码中存在一些更高级别的设计问题,但我们将无法理解您提供的有限示例。

Your question muddies the waters a bit, because you're mixing runtime and compile-time logic, because in your case the number and types of function arguments depends on the runtime value of something.

You're now stuck with two different options: it is possible to make this work (even in just C++14), but any call site that doesn't pass the correct arguments will not be detected until runtime. The way to do so is with the help of std::enable_if_t, decltype() and std::declval. I've done this for your example, and the following compiles for me in C++14 mode:

#include <iostream>
#include <type_traits>
#include <stdexcept>

enum class Fruit {
Apple,
Orange,
Pear,
};

void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();

struct Processor
{
    template<typename... Ts, typename = decltype(processApple(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Apple>, Ts&&... ts)
    {
        processApple(std::forward<Ts>(ts)...);
    }

    template<typename... Ts, typename = decltype(processOrange(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Orange>, Ts&&... ts)
    {
        processOrange(std::forward<Ts>(ts)...);
    }

    template<typename... Ts, typename = decltype(processPear(std::forward<Ts>(std::declval<Ts>())...))>
    static void process(std::integral_constant<Fruit, Fruit::Pear>, Ts&&... ts)
    {
        processPear(std::forward<Ts>(ts)...);
    }

    [[noreturn]] static void process(...)
    {
        // While this is inserted, it should never be called in practice,
        // unless there's a programming error.
        throw std::invalid_argument("Invalid argument specified to processFruit().");
    }
};

template<typename... Args>
void processFruit(Fruit fruit_type, Args&&... args) {
    switch (fruit_type) {
    case Fruit::Apple:
        Processor::process(std::integral_constant<Fruit, Fruit::Apple>(), std::forward<Args>(args)...);
        break;
    case Fruit::Orange:
        Processor::process(std::integral_constant<Fruit, Fruit::Orange>(), std::forward<Args>(args)...);
        break;
    case Fruit::Pear:
        Processor::process(std::integral_constant<Fruit, Fruit::Pear>(), std::forward<Args>(args)...);
        break;
    default:
        break;
    }
    postProcessing();
    return;
}

void processApple(int a, int b)
{
    std::cout << "Apple: " << a << " // " << b << std::endl;
}

void processOrange(int c)
{
    std::cout << "Orange: " << c << std::endl;
}

void processPear(double d)
{
    std::cout << "Pear: " << d << std::endl;
}

void postProcessing()
{
    std::cout << "Post processing" << std::endl;
}

int main()
{
    processFruit(Fruit::Apple, 4, 8);
    processFruit(Fruit::Orange, 15);
    processFruit(Fruit::Pear, 1.234);
    // The following will only throw an exception, but not fail to compile
    //processFruit(Fruit::Pear, 1.234, 77);
    return 0;
}

(The struct Processor is just to clean up the namespace, they could be global functions.) Problem here is that the compiler can't detect a wrong call, see the commented out call to processFruit(Fruit::Pear, 1.234, 77); that would generate an exception, but the compiler couldn't detect it at compile time.

In my eyes this is not very sensible though. Since the arguments depend on the Fruit type anyway, I don't really see how you could even perform a call to one of these functions when the Fruit argument is only known at runtime, because each call site will only work for a single type.

And if you do know that at compile time anyway, this could be done in a much simpler way via overloads, that also allows for much better compile-time diagnostics:

#include <iostream>
#include <type_traits>

enum class Fruit {
Apple,
Orange,
Pear,
};

void processApple(int a, int b);
void processOrange(int c);
void processPear(double d);
void postProcessing();

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Apple>, Args&&... args)
{
    processApple(std::forward<Args>(args)...);
    // or put the code of processApple directly in here
}

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Orange>, Args&&... args)
{
    processOrange(std::forward<Args>(args)...);
    // or put the code of processOrange directly in here
}

template<typename... Args>
void processFruit2Helper(std::integral_constant<Fruit, Fruit::Pear>, Args&&... args)
{
    processPear(std::forward<Args>(args)...);
    // or put the code of processPear directly in here
}

template<Fruit f, typename... Args>
void processFruit2(Args&&... args)
{
    processFruit2Helper(std::integral_constant<Fruit, f>(), std::forward<Args>(args)...);
    postProcessing();
}

void processApple(int a, int b)
{
    std::cout << "Apple: " << a << " // " << b << std::endl;
}

void processOrange(int c)
{
    std::cout << "Orange: " << c << std::endl;
}

void processPear(double d)
{
    std::cout << "Pear: " << d << std::endl;
}

void postProcessing()
{
    std::cout << "Post processing" << std::endl;
}

int main()
{
    processFruit2<Fruit::Apple>(4, 8);
    processFruit2<Fruit::Orange>(15);
    processFruit2<Fruit::Pear>(1.234);

    // The following will fail to compile here (which is good)
    //processFruit2<Fruit::Pear>(1.234, 77);
    return 0;
}

That all said, I suspect there's some higher-level design problem in your code, but we won't be able to understand that with the limited example you've provided.

基于条件的远期变异论证

滿滿的愛 2025-02-16 19:54:57

问题不在您共享的代码中。您的方法或数据可能有问题。
我会在这里猜测,因为您没有共享完整的代码。

如果您使用数据遵循他们的文档,那么您可能会因为有各种各样的对象而陷入困境,并且它们具有一系列字符串。
这就是来自他们的示例的,您需要的是 item.value item.label 而不是 item

mounted() {
  this.list = this.states.map(item => {
    // here you need item.value and item.label
    return { value: `value:${item}`, label: `label:${item}` };
  });
}

但这只是一个示例,在这里您可能会从API中获取数据,因此您需要检查如何检查该数据是结构化的。

这是您的数据的完整示例 https://codepen.io/jakob_/jakob_/jakob_/pen/pen/grxmqqqn

Problem is not in code you shared. Probably something is wrong in your methods or data.
And I will guess here because you didn't share full code.

If you followed their documentation with your data then you probably stuck because you have array of objects and they have array of strings.
That is this part from their example and what you need is item.value and item.label instead of item:

mounted() {
  this.list = this.states.map(item => {
    // here you need item.value and item.label
    return { value: `value:${item}`, label: `label:${item}` };
  });
}

But this is just an example and here you probably get data from API so you need to check how that data is structured.

Here is full working example with your data https://codepen.io/jakob_/pen/GRxMQQN

El-select具有多个和对象的值

滿滿的愛 2025-02-16 04:16:31

诚然,它有点隐藏,但是您可以在 monetdbe-examples 存储库:

import monetdbe

database = '/tmp/movies.mdbe'    

with monetdbe.connect(database) as conn:
    conn.set_autocommit(True)
    conn.execute(
        """CREATE TABLE Movies
        (id SERIAL, title TEXT NOT NULL, "year" INTEGER NOT NULL)""")

因此,在此示例中,单个参数到 connect 只是您数据库目录的所需路径。这就是您(重新)启动一个数据库,该数据库以持久的方式存储其数据在文件系统上。

请注意,我已故意从实际存储库中的示例中删除了Python行,该示例以注释#开始,如果数据库已经存在。只是为了使答案中的示例持续。

我尚未运行代码,但我希望如果您连续两次运行此代码,则第二次运行将在执行语句上返回数据库错误,因为 Movies 表应该已经存在。

可以肯定的是,如果您希望数据在计算机的重新启动之间持续存在,请勿使用/tmp 目录。

It is a little bit hidden away admittedly, but you can check out the following code snipet from the movies.py example in the monetdbe-examples repository:

import monetdbe

database = '/tmp/movies.mdbe'    

with monetdbe.connect(database) as conn:
    conn.set_autocommit(True)
    conn.execute(
        """CREATE TABLE Movies
        (id SERIAL, title TEXT NOT NULL, "year" INTEGER NOT NULL)""")

So in this example the single argument to connect is just the desired path to your database directory. This is how you can (re)start a database that stores its data in a persistent way on a file system.

Notice that I have intentionally removed the python lines from the example in the actual repo that start with the comment # Removes the database if it already exists. Just to make the example in the answer persistent.

I haven't run the code but I expect that if you run this code twice consecutively the second run wil return a database error on the execute statement as the movies table should already be there.

And just to be sure, don't use the /tmp directory if you want your data to persist between restarts of your computer.

如何将内存的Monetdbe DB持续到本地磁盘

滿滿的愛 2025-02-16 02:14:29

在另一篇文章中找到了我的答案,希望它对其他人有所帮助:

https://stackoverflow.com/a/56344197/302613

为了确保出现此映射,您需要去控制
面板 - &GT;打开或关闭Windows功能 - &GT; .NET框架4.7
高级服务(或equiv .Net Ver) - &gt; WCF服务 - &GT; http
激活

Found my answer in another post, hope it helps someone else:

https://stackoverflow.com/a/56344197/302613

In order to make sure this mapping appears you need to go to control
panel -> turn windows features on or off -> .NET Framework 4.7
Advanced Services (or equiv .net ver) -> WCF Services -> HTTP
Activation

设置Visual Studio在Windows 11上使用本地II,给出了未找到网站的错误

滿滿的愛 2025-02-15 16:08:01

它有3个步骤:

1-在您的应用程序录音中添加SMS读取和接收权限:

   //in android
  <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

2-创建一种权限检查的方法。3-

 public async Task<PermissionStatus> CheckAndRequestSMSPermission()
        {
            PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.Sms>();

if (status == PermissionStatus.Granted)
                return status;

if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
            {
                // Prompt the user to turn on in settings
                // On iOS once a permission has been denied it may not be requested again from the application
                return status;
            }

if (Permissions.ShouldShowRationale<Permissions.Sms>())
            {
                // Prompt the user with additional information as to why the permission is needed
            }
           status = await Permissions.RequestAsync<Permissions.Sms>();
           return status;
        }

进行API调用并获取SMS并使用它。

private async void OnCounterClicked(object sender, EventArgs e)
        {
            var res= await  CheckAndRequestSMSPermission();
            if (res.Equals( PermissionStatus.Granted))
            {
#if ANDROID


               List<string> items=new List<string>();
                string INBOX = "content://sms/inbox";
                string[] reqCols = new string[] { "_id", "thread_id", "address", "person", "date", "body", "type" };
                Android.Net.Uri uri = Android.Net.Uri.Parse(INBOX);
                Android.Database.ICursor cursor = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.ContentResolver.Query(uri, reqCols, null, null, null);


       if (cursor.MoveToFirst())
        {
            do
            {
                        string messageId = cursor.GetString(cursor.GetColumnIndex(reqCols[0]));
                        string threadId = cursor.GetString(cursor.GetColumnIndex(reqCols[1]));
                        string address = cursor.GetString(cursor.GetColumnIndex(reqCols[2]));
                        string name = cursor.GetString(cursor.GetColumnIndex(reqCols[3]));
                        string date = cursor.GetString(cursor.GetColumnIndex(reqCols[4]));
                        string msg = cursor.GetString(cursor.GetColumnIndex(reqCols[5]));
                        string type = cursor.GetString(cursor.GetColumnIndex(reqCols[6]));


                       items.Add(messageId + (","
                                + (threadId + (","
                                + (address + (","
                                + (name + (","
                                + (date + (" ,"
                                + (msg + (" ," + type))))))))))));


           } while (cursor.MoveToNext());


       }
#endif
            }
        }

It has 3 step:

1- add sms read and receive permission in your app manifast:

   //in android
  <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />

2- create a method for permission check..

 public async Task<PermissionStatus> CheckAndRequestSMSPermission()
        {
            PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.Sms>();

if (status == PermissionStatus.Granted)
                return status;

if (status == PermissionStatus.Denied && DeviceInfo.Platform == DevicePlatform.iOS)
            {
                // Prompt the user to turn on in settings
                // On iOS once a permission has been denied it may not be requested again from the application
                return status;
            }

if (Permissions.ShouldShowRationale<Permissions.Sms>())
            {
                // Prompt the user with additional information as to why the permission is needed
            }
           status = await Permissions.RequestAsync<Permissions.Sms>();
           return status;
        }

3- Make a api call and get sms and use that.

private async void OnCounterClicked(object sender, EventArgs e)
        {
            var res= await  CheckAndRequestSMSPermission();
            if (res.Equals( PermissionStatus.Granted))
            {
#if ANDROID


               List<string> items=new List<string>();
                string INBOX = "content://sms/inbox";
                string[] reqCols = new string[] { "_id", "thread_id", "address", "person", "date", "body", "type" };
                Android.Net.Uri uri = Android.Net.Uri.Parse(INBOX);
                Android.Database.ICursor cursor = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.ContentResolver.Query(uri, reqCols, null, null, null);


       if (cursor.MoveToFirst())
        {
            do
            {
                        string messageId = cursor.GetString(cursor.GetColumnIndex(reqCols[0]));
                        string threadId = cursor.GetString(cursor.GetColumnIndex(reqCols[1]));
                        string address = cursor.GetString(cursor.GetColumnIndex(reqCols[2]));
                        string name = cursor.GetString(cursor.GetColumnIndex(reqCols[3]));
                        string date = cursor.GetString(cursor.GetColumnIndex(reqCols[4]));
                        string msg = cursor.GetString(cursor.GetColumnIndex(reqCols[5]));
                        string type = cursor.GetString(cursor.GetColumnIndex(reqCols[6]));


                       items.Add(messageId + (","
                                + (threadId + (","
                                + (address + (","
                                + (name + (","
                                + (date + (" ,"
                                + (msg + (" ," + type))))))))))));


           } while (cursor.MoveToNext());


       }
#endif
            }
        }
  • you can see more in here.

在毛伊岛Android中阅读SMS以获取程序

滿滿的愛 2025-02-15 13:49:22

我建议开始围绕服务,集团,存储库实施单元测试。然后在有一些逻辑的地方开始测试视图小部件。

之后,也许在复杂方案周围进行了一些集成测试,例如如果我将许多单元测试结合在一起以模拟登录,会发生什么。

I suggest to start implementing unit test around service, bloc, repository. Then start test view widget where there is some logic.

After that maybe some integration test around complexe scenario like what happen if I combine many unit test together to simulate a login.

如何开始测试一个大型项目的扑面游戏?

滿滿的愛 2025-02-15 08:25:07

不确定在这里了解您的目标,但这是迭代行上的一种方法:

import pandas as pd

eIP = pd.DataFrame({"IP": ["a", "b", "c"]})

for _, row in eIP.iterrows():
    print(row.values[0])

# Output
a
b
c

您还可以获取这样的价值的字典:

print(eIP.to_dict()["IP"])
# Output
{0: 'a', 1: 'b', 2: 'c'}

Not sure to understand your goal here, but here is one way to iterate on rows:

import pandas as pd

eIP = pd.DataFrame({"IP": ["a", "b", "c"]})

for _, row in eIP.iterrows():
    print(row.values[0])

# Output
a
b
c

You can also get a dictionary of the values like this:

print(eIP.to_dict()["IP"])
# Output
{0: 'a', 1: 'b', 2: 'c'}

使用Python中使用特定列和Excel工作簿中的单元格

滿滿的愛 2025-02-14 22:21:14

基本上,您可以将数据保存为 userDefaults 中的字符串数组

func save() {
   UserDefaults.standard.set(items.map(\.title), forKey: "items")
} 

func load() {
   let savedItems = UserDefaults.standard.stringArray(forKey: "items") ?? []
   items = savedItems.map(Item.init)
}

,并在 .onappear 中调用 load 。

但是,如果有大量项目考虑文档文件夹或核心数据中的文件

Basically you can save the data as String array in UserDefaults

func save() {
   UserDefaults.standard.set(items.map(\.title), forKey: "items")
} 

func load() {
   let savedItems = UserDefaults.standard.stringArray(forKey: "items") ?? []
   items = savedItems.map(Item.init)
}

and call load in .onAppear.

However if there is a huge amount of items consider a file in the Documents folder or Core Data

持续存储用户在swiftui中添加的列表项目

滿滿的愛 2025-02-14 18:20:48
  1. 请使用 {renderlist()} 而不是 {renderList}
  2. 使用 {renderList()} &lt;/datatable.header&gt; &lt;/datatable&gt; ...而不是之后&lt;/datatable&gt;
  1. Please use {renderList()} instead of {renderList}.
  2. Use {renderList()} between </DataTable.Header> and </DataTable>...and not after </DataTable>.

如何将数据获取到我的DataTable中

滿滿的愛 2025-02-14 14:14:27

这完全取决于您想要的效果,但是对于所示的简单案例,您只需删除第一个(或最后一个,具体取决于您朝哪个方向)元素,然后将其放在缩略图集的末端(或开始)。

这也使事情变得更加响应,因为如果您不想,您不必以PX术语来修复宽度,因为不必记住它们即可移动元素。

const buttonLeft = document.getElementById('slide_left')
const buttonRight = document.getElementById('slide_right')

const container = document.getElementById('slider');

buttonLeft.addEventListener('click', function() {
  const last = document.querySelector('#slider > :last-child');
  last.remove();
  container.prepend(last);
})

buttonRight.addEventListener('click', function() {
  const first = document.querySelector('#slider > :first-child');
  first.remove();
  container.append(first);
})
body {
  background-color: #555;
  height: 100vh;
  display: grid;
  align-items: center;
  justify-items: center;
  font-family: 'Helvetica';
}

div#slide_wrapper {
  width: 440px;
  display: flex;
  justify-content: space-between;
  height: fit-content;
}

div#slider {
  width: 350px;
  display: flex;
  height: fit-content;
  flex-wrap: nowrap;
  overflow: hidden;
}

div.thumbnail {
  min-width: 80px;
  min-height: 80px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 30px;
}

div.thumbnail:not(:last-child) {
  margin-right: 10px;
}

div.thumbnail.c1 {
  background-color: darkturquoise;
}

div.thumbnail.c2 {
  background-color: goldenrod;
}

div.thumbnail.c3 {
  background-color: rebeccapurple;
}

div.thumbnail.c4 {
  background-color: salmon;
}

div.thumbnail.c5 {
  background-color: lawngreen;
}

div.thumbnail.c6 {
  background-color: sienna;
}

div.thumbnail.c7 {
  background-color: bisque;
}

div.thumbnail.c8 {
  background-color: navy;
}

div#slide_wrapper>button {
  height: fit-content;
  align-self: center;
  font-size: 24px;
  font-weight: 800;
  border: none;
  outline: none;
}

div#slide_wrapper>button:hover {
  cursor: pointer;
}
<div id="slide_wrapper">
  <button id="slide_left" class="slide_arrow">❮</button>
  <div id="slider">
    <div class="thumbnail c1 active">1</div>
    <div class="thumbnail c2">2</div>
    <div class="thumbnail c3">3</div>
    <div class="thumbnail c4">4</div>
    <div class="thumbnail c5">5</div>
    <div class="thumbnail c6">6</div>
    <div class="thumbnail c7">7</div>
    <div class="thumbnail c8">8</div>
  </div>
  <button id="slide_right" class="slide_arrow">❯</button>
</div>

It depends on exactly what effect you want, but for the simple case illustrated you can just remove the first (or last, depending on which direction you are going) element and put it to the end (or beginning) of the set of thumbnails.

That makes things a bit more responsive too as you don't have to fix the widths in px terms if you don't want to as they don't have to be remembered in order to move the elements.

const buttonLeft = document.getElementById('slide_left')
const buttonRight = document.getElementById('slide_right')

const container = document.getElementById('slider');

buttonLeft.addEventListener('click', function() {
  const last = document.querySelector('#slider > :last-child');
  last.remove();
  container.prepend(last);
})

buttonRight.addEventListener('click', function() {
  const first = document.querySelector('#slider > :first-child');
  first.remove();
  container.append(first);
})
body {
  background-color: #555;
  height: 100vh;
  display: grid;
  align-items: center;
  justify-items: center;
  font-family: 'Helvetica';
}

div#slide_wrapper {
  width: 440px;
  display: flex;
  justify-content: space-between;
  height: fit-content;
}

div#slider {
  width: 350px;
  display: flex;
  height: fit-content;
  flex-wrap: nowrap;
  overflow: hidden;
}

div.thumbnail {
  min-width: 80px;
  min-height: 80px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 30px;
}

div.thumbnail:not(:last-child) {
  margin-right: 10px;
}

div.thumbnail.c1 {
  background-color: darkturquoise;
}

div.thumbnail.c2 {
  background-color: goldenrod;
}

div.thumbnail.c3 {
  background-color: rebeccapurple;
}

div.thumbnail.c4 {
  background-color: salmon;
}

div.thumbnail.c5 {
  background-color: lawngreen;
}

div.thumbnail.c6 {
  background-color: sienna;
}

div.thumbnail.c7 {
  background-color: bisque;
}

div.thumbnail.c8 {
  background-color: navy;
}

div#slide_wrapper>button {
  height: fit-content;
  align-self: center;
  font-size: 24px;
  font-weight: 800;
  border: none;
  outline: none;
}

div#slide_wrapper>button:hover {
  cursor: pointer;
}
<div id="slide_wrapper">
  <button id="slide_left" class="slide_arrow">❮</button>
  <div id="slider">
    <div class="thumbnail c1 active">1</div>
    <div class="thumbnail c2">2</div>
    <div class="thumbnail c3">3</div>
    <div class="thumbnail c4">4</div>
    <div class="thumbnail c5">5</div>
    <div class="thumbnail c6">6</div>
    <div class="thumbnail c7">7</div>
    <div class="thumbnail c8">8</div>
  </div>
  <button id="slide_right" class="slide_arrow">❯</button>
</div>

这些幻灯片可以循环吗?

滿滿的愛 2025-02-14 11:23:04

如果您确定所有配置都是正确的,那么由于将null值作为ciphered发送到降低或平面文本以供ENRIPTION,因此可能会得到此例外。

If you sure all configurations are right, so that may you get this exception due to sending a null value as a ciphered to decript or a plane text to encript.

给定最终块未正确填充

滿滿的愛 2025-02-14 08:43:15

这是因为您的工厂构造函数并非无参数,并且当服务提供商试图实例化工厂时,它没有价值来传递“示例”变量。

有两种可能的解决方案:

1-更改工厂的设计,并将“示例”作为变量创建方法而不是构造函数。

2-这样注册工厂:

services.AddSingleton(s => new Factory(s.GetService<A>(), "desired string"));

顺便说一句,我不知道您实施该工厂类的用例是什么,但似乎并不是实施它的正确方法。我建议您事先看看:

工厂设计模式

It is because your Factory constructor is not parameter-less, and when the service provider tries to instantiate the Factory, it has no value to pass for the "sample" variable.

There are two possible solutions to this:

1- Changing the design of your factory, and passing the "sample" as a variable to Create method instead of the constructor.

OR

2- Registering the factory like this:

services.AddSingleton(s => new Factory(s.GetService<A>(), "desired string"));

Btw, I don't know what is the use case that you have for implementing this factory class, but it doesn't seem the right way of implementing it. I suggest you take a look at this beforehand:

Factory Design Pattern

无法解析类型的服务&#x27; System.String&#x27;在尝试激活.NET核心的同时

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文