IOS Dictonary获得特定单词的定义

时间:2017-08-17 11:17:43

标签: ios

我希望在我的应用程序中访问iOS字典。在iOS的构建库中是否有任何提供特定单词的定义。

我找到了许多第三方API来完成这项工作,但他们已经获得了报酬。

寻找最佳解决方案......

2 个答案:

答案 0 :(得分:0)

Swift 3

  if UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm: "word") {
            let libraryVC = UIReferenceLibraryViewController(term: "word")
            self.present(libraryVC, animated: true, completion: nil)
        }

守则本身很清楚,不需要解释

答案 1 :(得分:0)

是的,您可以尝试UIReferenceLibraryViewController

除了定义,它还包括检查是否定义了给定的单词。您可以按如下方式使用它:

<强>目标-C:

/**
 * Given a grid object and an array containing the data indexes 
 * of the columns that we want to display, this function should
 * make the grid to display only the given columns, and in the
 * order as they appear on the columns array
 * @param {Ext.grid.Panel} grid
 * @param {String[]} columnsConfiguration
 */
setColumnsPreferences: function(grid, columnsConfiguration) {
    var gridView = grid.getView();
    var headerContainer = gridView.getHeaderCt();
    var columns = headerContainer.getGridColumns();

    var columnsByDataIndex = {};
    for (var i = 0; i < columns.length; i++)
    {
        // save columns by data index for easier access later on
        var column = columns[i];
        var dataIndex = column.dataIndex;
        columnsByDataIndex[dataIndex] = column;
    }

    for (var newIndex = 0; newIndex < columnsConfiguration.length; newIndex++)
    {
        // Note that you have to start from the lowest new index
        // If you don't, your columns will not be ordered propertly
        var dataIndex = columnsConfiguration[newIndex];
        // get column from prepared object
        var column = columnsByDataIndex[dataIndex];
        var oldIndex = column.getIndex();
        // move column from old index to new index
        headerContainer.move(oldIndex, newIndex);
    }

    // refresh grid view at the end to apply changes
    gridView.refresh();
},

<强>夫特:

if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:@"definition"]) {
    UIReferenceLibraryViewController* ref = 
        [[UIReferenceLibraryViewController alloc] initWithTerm:@"definition"];
    [currentViewController presentViewController:ref animated:YES completion:nil];
}