Database applescript/xcode中的数据库

Database applescript/xcode中的数据库,database,xcode,macos,youtube,applescript,Database,Xcode,Macos,Youtube,Applescript,所以我在youtube上看了这段关于如何建立数据库的视频。我真的很喜欢这个主意,但我无法使它发挥作用 有人能帮我吗 另外,您还可以告诉我如何使用xcode:-此视频讨论的脚本粘贴在视频评论中。它不能正常工作,因为所有的新行字符都被Youtube删除了。我更改了代码以按预期工作。将下面提到的代码复制到AppleScript编辑器并点击run,它现在应该可以正常工作了 请注意,这不是数据库。此脚本仅获取您的输入,并将其与一些预定义值逐一进行比较。当马赫数出现时,会显示一个对话框 注: 这个代码很难看

所以我在youtube上看了这段关于如何建立数据库的视频。我真的很喜欢这个主意,但我无法使它发挥作用

有人能帮我吗


另外,您还可以告诉我如何使用xcode:-

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

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

注: 这个代码很难看。你最好学会使用循环和列表。这使您的代码更加高效

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

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

请注意,数据库中的一条记录如下所示,您只需在扩展数据库时添加和删除记录。 {人名:Sam Price,成员编号: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

在Xcode中构建数据库?我希望你好运……你没有说明它是如何不起作用的。它不编译吗?它没有给出预期的结果吗?如果您在使用提供的AppleScript时遇到问题,尽管您可以在Xcode中构建AppleScript应用程序,但此时跳入Xcode可能是不明智的。现在只需使用脚本编辑器,并尝试让它的一部分工作。