applescript/xcode 中的数据库

发布于 2024-10-25 05:10:07 字数 234 浏览 5 评论 0原文

所以我在 youtube 上观看了这个视频 (http://www.youtube.com/watch?v=l_PLHuhlAJU )关于如何创建数据库。我很喜欢这个主意,但我无法让它发挥作用。

任何人都可以帮助我

P.S 你也可以告诉我如何使用 xcode 来做到这一点:-)

so I watched this video on youtube (http://www.youtube.com/watch?v=l_PLHuhlAJU) on how to make a database. I rellay like the idea but I cant get it to work.

can anyone help me

P.S you can also tell me how to do this with xcode :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁人与我共长歌 2024-11-01 05:10:07

为了扩展 Anne 的评论,这里有一个更简单、更高效的数据库。在脚本的顶部创建数据库。您只需在数据库中添加和删除记录即可。其余代码仅搜索数据库并显示结果。

请注意,数据库中的一条记录如下所示,您只需在扩展数据库时添加和删除记录即可。
{personName:"Sam Price", memberNumber:"1", 电话号码:"123"}

set myDatabase to {{personName:"Sam Price", memberNumber:"1", phoneNumber:"123"}, {personName:"Dave Blogg", memberNumber:"2", phoneNumber:"1234"}, {personName:"jack tumb", memberNumber:"3", phoneNumber:"12345"}}

set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1)

set foundRecord to missing value
repeat with aRecord in myDatabase
    ignoring white space
        ignoring case
            if (personName of aRecord) contains x then
                set foundRecord to aRecord
                exit repeat
            end if
        end ignoring
    end ignoring
end repeat

if foundRecord is missing value then
    set dialogText to "The person \"" & x & "\" cannot be found in the database!"
else
    set dialogText to (personName of foundRecord) & ", member number: " & (memberNumber of foundRecord) & ", phone number: " & (phoneNumber of foundRecord)
end if

display dialog dialogText buttons {"OK"} default button 1

Just to expand on Anne's comments, here's a much easier and more efficient database. At the top of the script you create your database. You just add and remove records from the database there. The rest of the code just searches the database and shows the results.

Note that one record in the database looks like this, and you just add and remove records as you expand your database.
{personName:"Sam Price", memberNumber:"1", phoneNumber:"123"}

set myDatabase to {{personName:"Sam Price", memberNumber:"1", phoneNumber:"123"}, {personName:"Dave Blogg", memberNumber:"2", phoneNumber:"1234"}, {personName:"jack tumb", memberNumber:"3", phoneNumber:"12345"}}

set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1)

set foundRecord to missing value
repeat with aRecord in myDatabase
    ignoring white space
        ignoring case
            if (personName of aRecord) contains x then
                set foundRecord to aRecord
                exit repeat
            end if
        end ignoring
    end ignoring
end repeat

if foundRecord is missing value then
    set dialogText to "The person \"" & x & "\" cannot be found in the database!"
else
    set dialogText to (personName of foundRecord) & ", member number: " & (memberNumber of foundRecord) & ", phone number: " & (phoneNumber of foundRecord)
end if

display dialog dialogText buttons {"OK"} default button 1
向日葵 2024-11-01 05:10:07

该视频讨论的脚本粘贴在视频评论中。它无法正常工作,因为所有换行符都被 Youtube 删除了。我更改了代码以按预期工作。将下面提到的代码复制到AppleScript编辑器并点击运行,它现在应该可以正常工作了。

请注意,这不是数据库。该脚本仅获取您的输入并将其与一些预定义的值进行一一比较。当机器出现时,它会显示一个对话框。

注:
这段代码非常难看。您最好学习使用循环和列表。这使您的代码更加高效。

set s to "sam price"
set d to "dave blogg"
set j to "jack tumb"
set m to "max dog"
set f to "fabio james"
set sa to "sara parker"
set o to "oliver jones"
set b to "bob samuel"
set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1)
ignoring white space
    ignoring case
        if x contains s then
            display dialog "Sam Price,   member number: 1, phone number: 123" buttons {"OK"}
        end if
        if x contains d then
            display dialog "Dave Blogg, member number: 2, phone number: 1234" buttons {"OK"}
        end if
        if x contains j then
            display dialog "jack tumb,   member number: 3, phone number: 12345" buttons {"OK"}
        end if
        if x contains m then
            display dialog "Max Dog, member number: 4, phone number: 12345" buttons {"OK"}
        end if
        if x contains f then
            display dialog "Fabio James, member number: 5, phone number: 123456" buttons {"OK"}
        end if
        if x contains sa then
            display dialog "Sara Parker, member number: 6, phone number: 1234567" buttons {"OK"}
        end if
        if x contains o then
            display dialog "Oliver Jones, member number: 7, phone number: 12345678" buttons {"OK"}
        end if
        if x contains b then
            display dialog "Bob samuel, member number: 8,  phone number: 12345678" buttons {"OK"}
        end if
    end ignoring
end ignoring

The script discussed by this video is pasted in the video comment. It's not working properly because all new line characters are removed by Youtube. I changed the code to work as intended. Copy the code mentioned below to AppleScript Editor and hit run, it should work properly now.

Please note this is NO database. This script only gets your input and compares it one-by-one with some pre-defined values. When a mach occurs, it shows a dialog.

Note:
This code is very ugly. You better learn using loops and lists. This makes your code much more efficient.

set s to "sam price"
set d to "dave blogg"
set j to "jack tumb"
set m to "max dog"
set f to "fabio james"
set sa to "sara parker"
set o to "oliver jones"
set b to "bob samuel"
set x to text returned of (display dialog "Search for a member" default answer "ENTER THE NAME HERE!" buttons {"Search"} default button 1)
ignoring white space
    ignoring case
        if x contains s then
            display dialog "Sam Price,   member number: 1, phone number: 123" buttons {"OK"}
        end if
        if x contains d then
            display dialog "Dave Blogg, member number: 2, phone number: 1234" buttons {"OK"}
        end if
        if x contains j then
            display dialog "jack tumb,   member number: 3, phone number: 12345" buttons {"OK"}
        end if
        if x contains m then
            display dialog "Max Dog, member number: 4, phone number: 12345" buttons {"OK"}
        end if
        if x contains f then
            display dialog "Fabio James, member number: 5, phone number: 123456" buttons {"OK"}
        end if
        if x contains sa then
            display dialog "Sara Parker, member number: 6, phone number: 1234567" buttons {"OK"}
        end if
        if x contains o then
            display dialog "Oliver Jones, member number: 7, phone number: 12345678" buttons {"OK"}
        end if
        if x contains b then
            display dialog "Bob samuel, member number: 8,  phone number: 12345678" buttons {"OK"}
        end if
    end ignoring
end ignoring
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文