Int32 can't be converted to gcl_queue_flags - macos

My attempt to use OpenCL with the Swift language (using xcode6 Dp4, Yosemite DP4) fails:
import Cocoa
import OpenCL
-
-
var queue: dispatch_queue_t = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, nil)
-
-
An error message comes up at "var queue ..."-line; "Int32 can't be converted to gcl_queue_flags". The line of code works perfectly when using Objective-C or C. Testing OpenCL (and GCDas well) seems not work in playground.

This is an issue with the way the CL_DEVICE_TYPE_GPU macro is imported to Swift — it's an Int32, but the function takes UInt64. So you can use cl_queue_flags(CL_DEVICE_TYPE_GPU) to convert it. You might also want to file a bug.

Related

freeimage 3.17 library build failing on Mac OS X: fails with C++11 narrowing error... any ideas?

With not having any understanding of C++ (I'm teaching myself Swift), I'm struggling a bit to get around this one - but ideally would love to be able to expose some of the functionality in the FreeImage library in my project.
It appears that only one module is generating any errors: dcraw_common.cpp - and the lines in error are those from the following entry list where there is a value of 0x80 or above. From the investigations I've done, it would appear that these values are too large for a signed char (max 128?), yet the list also includes negative numbers, and so it can't use an unsigned char.
Any help would be most gratefully received.
Here's an example of the error message generated by the make process:
Source/LibRawLite/./internal/dcraw_common.cpp:4543:19: error: constant expression evaluates to 136 which cannot be narrowed to type 'signed char'
[-Wc++11-narrowing]
+1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40,
^~~~
And here's the code:
void CLASS vng_interpolate()
{
static const signed char *cp, terms[] = {
-2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01,
-2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01,
-2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03,
-2,+1,-1,+0,0,0x04, -2,+1,+0,-1,1,0x04, -2,+1,+0,+0,0,0x06,
-2,+1,+0,+1,0,0x02, -2,+2,+0,+0,1,0x04, -2,+2,+0,+1,0,0x04,
-1,-2,-1,+0,0,0x80, -1,-2,+0,-1,0,0x01, -1,-2,+1,-1,0,0x01,
-1,-2,+1,+0,1,0x01, -1,-1,-1,+1,0,0x88, -1,-1,+1,-2,0,0x40,
-1,-1,+1,-1,0,0x22, -1,-1,+1,+0,0,0x33, -1,-1,+1,+1,1,0x11,
-1,+0,-1,+2,0,0x08, -1,+0,+0,-1,0,0x44, -1,+0,+0,+1,0,0x11,
-1,+0,+1,-2,1,0x40, -1,+0,+1,-1,0,0x66, -1,+0,+1,+0,1,0x22,
-1,+0,+1,+1,0,0x33, -1,+0,+1,+2,1,0x10, -1,+1,+1,-1,1,0x44,
-1,+1,+1,+0,0,0x66, -1,+1,+1,+1,0,0x22, -1,+1,+1,+2,0,0x10,
-1,+2,+0,+1,0,0x04, -1,+2,+1,+0,1,0x04, -1,+2,+1,+1,0,0x04,
+0,-2,+0,+0,1,0x80, +0,-1,+0,+1,1,0x88, +0,-1,+1,-2,0,0x40,
+0,-1,+1,+0,0,0x11, +0,-1,+2,-2,0,0x40, +0,-1,+2,-1,0,0x20,
+0,-1,+2,+0,0,0x30, +0,-1,+2,+1,1,0x10, +0,+0,+0,+2,1,0x08,
+0,+0,+2,-2,1,0x40, +0,+0,+2,-1,0,0x60, +0,+0,+2,+0,1,0x20,
+0,+0,+2,+1,0,0x30, +0,+0,+2,+2,1,0x10, +0,+1,+1,+0,0,0x44,
+0,+1,+1,+2,0,0x10, +0,+1,+2,-1,1,0x40, +0,+1,+2,+0,0,0x60,
+0,+1,+2,+1,0,0x20, +0,+1,+2,+2,0,0x10, +1,-2,+1,+0,0,0x80,
+1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40,
+1,+0,+2,+1,0,0x10
}, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 };
...
C++11 prevents 'narrowing conversions' like that. Early versions of C++ would accept them. I think this patch to the source of dcraw_common.cpp should fix it.
https://gist.github.com/conchurnavid/ac19c8e882f1835f0310
There's a duplicate question here. Building FreeImage 3.16.0 for Android
The most usable solution I found to this issue was the following GitHub posting: https://github.com/danoli3/FreeImage. Here some kind soul appears to have successfully built the 3.17.0 library and uploaded it. I've found that works just fine.
Please bear in mind however that it's been built with a hard-coded path of /opt/local/lib - which may be an issue when you come to implementation, since your app will be looking for it there, not bundled with the app. I did find this LiveCode post aided my understanding in that regard a lot.
Hope this helps.

Swift 2, convert a String into an Int

I'm using Xcode 7 Beta 3 and reading through Swift 2.2 document. I'm trying to compile this example found in the Basics section of the document:
let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)
It is supposed to convert a string into an optional int. However Xcode gives the error:
Cannot call value of non-function type 'int'
I was working on Xcode 7.2.1, then I knew that Swift 2.2 is packaged with Xcode 7.3 Beta 3, so I downloaded that to try, but the same error happens.
So, is the document wrong? and how to achieve the string into int conversion?
There is nothing wrong with your code, I tested and ran your exact code in Xcode 7.2:
let possibleNumber = "123"
let convertedNumber = Int(possibleNumber)
print("\(convertedNumber)")
It complied, ran within an app of mine, and printed the Int value 123.
Perhaps the error is being thrown from another area of code in your Xcode app, other then the code you think is throwing the error....
Perhaps you are not referencing the version of Swift you think you are...
Note, you should use if let with any conversion attempt:
if let convertedNumber = Int(possibleNumber) {
}
The if let should be used for a conversion no matter how remote the possibility of failure.

Can't properly use NSEventModifierFlags in Swift 2.0

I'm trying to develop a little Mac app in Xcode 7 (7A120f), but it isn't letting me. Allegedly, this code snippet is faulty:
let composeHotKey = DDHotKey(keyCode: UInt16(kVK_Return), modifierFlags: NSEventModifierFlags.CommandKeyMask | NSEventModifierFlags.ShiftKeyMask, task: {
event in
self.doSomething()
})
Trying to compile my app results in an Xcode build failure with the following error message while it highlights the NSEventModifierFlags.CommandKeyMask | NSEventModifierFlags.ShiftKeyMask part:
Binary operator '|' cannot be applied to two NSEventModifierFlags operands
What's going on? According to everything I find online, I should be able to do that.
In Swift 2, bit field style enums like NSEventModifierFlags are imported to Swift as subtypes of OptionSetType. Those don't use bit-twiddling syntax like in C (or Swift 1.x).
Instead, such types use methods and syntax reflecting set logic. You can create one with a set literal:
let composeHotKey = DDHotKey(keyCode: UInt16(kVK_Return), modifierFlags: .CommandKeyMask.rawValue | .ShiftKeyMask.rawValue, task: {
event in
self.doSomething()
})
NSEventModifierFlags(rawValue: NSEventModifierFlags.NumericPadKeyMask.rawValue | NSEventModifierFlags.NumericPadKeyMask.rawValue)

AVSpeechUtterance Not Working

In IOS 8 AVSpeechUtterance is Not Working. Every time I use AVSpeechSynthesizer along with AVSpeechUtterance, I get "Speech initialization error: 2147483665". The same code works fine for IOS 7.1 I have a very large text to convert to speech, and using Google TTS won't allow me to use more than 100 characters at a time. How can I implement text-to-speech in IOS 8? Any help will be appreciated.
See this topic, and linked question also: AVSpeechSynthesizer iOS 8 Issues
For me, TTS on iOS work only on real device, not simulator. But iOS8 still have some problems with voices, some workaround mentioned in questions above.
Also, please mention this (user should set some settings): Using AVSpeechSynthesizer/AVSpeechUtterance for Text-To-Speech will not work if SpeakSelection is not enabled in device's Accessiblity settings
First import Speech
import Speech
Secondly define global variable for AVSpeechSynthesizer
let speakTalk = AVSpeechSynthesizer()
Create function Audio to take input as string
func Audio(Input : String)
{
let speakText = AVSpeechUtterance(string: "\(Input)")
speakText.rate = 0.5
speakText.pitchMultiplier = 1.7
speakTalk.speak(speakText)
}
call func Audio()
Audio(Input : "Hello")

Swift NSDate Xcode error - SourceKitService terminated

import Foundation
var currentTime = NSDate()
println("It is currently", currentTime)
This Swift code is very simple and should work, correct? Why am i receiving an error that says "SourceKitService terminated - editor functionality currently limited"
Am I doing something wrong or is it the beta's fault?
You would use string interpolation as Jack Wu suggested in the first comment:
println("It is currently \(currentTime)")
The println primary function does not take multiple arguments. You could also use
println(currentTime)
However, the fact that your first (syntax error) attempt causes Xcode 6 to crash (at least it does for me) is certainly a bug. You should just get an issue reported.

Resources