gpt4 book ai didi

objective-c - 从 Ruby on Rails 执行 Objective-C

转载 作者:数据小太阳 更新时间:2023-10-29 07:38:26 27 4
gpt4 key购买 nike

我想在我的 Rails 应用程序中执行以下 Objective-C 代码:

CFMutableStringRef inputString = CFStringCreateMutableCopy(kCFAllocatorDefault, 32,     CFSTR("общей"));
CFLocaleRef locale = CFLocaleCreate(kCFAllocatorDefault, CFSTR("ru"));

CFStringTransform(inputString, NULL, kCFStringTransformStripDiacritics, false);
CFStringLowercase(inputString, locale);


NSLog(@"%@", (NSString *)inputString);

CFRelease(locale);
CFRelease(inputString);

它基本上输出输入字符串的小写、无变音符号版本。我在 Snow Leopard 服务器上运行。

我该怎么做(不使用 MacRuby,这在这里似乎有点矫枉过正)?我听说过 Ruby 扩展,但在我的案例中找不到任何资源。

最佳答案

你或许可以使用 ffi 来做到这一点,但它需要输入一堆功能规范。调用 Core Foundation 函数的小测试用例:

require 'ffi'

module CF
extend FFI::Library
ffi_lib '/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation'
attach_function :CFAbsoluteTimeGetCurrent, [], :double
end

puts CF.CFAbsoluteTimeGetCurrent

关于objective-c - 从 Ruby on Rails 执行 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8161185/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com