The following code:
var mutableDataP = UnsafeMutablePointer<Int16>(audioBuffer.mData)
let stereoSampleArray = UnsafeMutableBufferPointer(
start: mutableDataP,
count: nBytesInBuffer/sizeof(Int16) // Int16 audio samples
)
gives the following error:
Cannot convert value of type 'UnsafeMutablePointer' to expected
argument type 'UnsafeMutablePointer<_>'
What is an UnsafeMutablePointer<__> and how do I cast to it? I tried all the casting variations I could think of and got un-understandable diagnostics for each and I've run out of ideas. I find the documentation on the various UnsafeMutablePointer types unhelpful, and no mention at all of '<_>'.
Try this change:
let stereoSampleArray = withUnsafeMutablePointer(to: &audioBuffer.mData){
return UnsafeMutableBufferPointer(
start: $0,
count: nBytesInBuffer/MemoryLayout<Int16>.size // Int16 audio samples
)
}
Where audioBuffer.mData is a var
Related
The following code gives the error
Expected 'while' in 'do-while' loop
if let path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
do {
let stringFromFile = try String(contentsOfFile:path, encoding: NSUTF8StringEncoding)
var chapters: [String] = stringFromFile.componentsSeparatedByString("#")
chapters.removeAtIndex(0)
} catch {
print((error))
}
}
it was working fine before, but now it's giving me an error. Does anyone know why?
That code works for me as-is in the Playground with the appropriate Chapters.txt file in the Resources folder; XCode 7.1 Build 7B60. Did you try Shift-Command-K for a Clean Build?
Something does not seem right with your error message. With Swift 2.0, there are no more do-while loops. They have been replaced by repeat-while loops instead. As your code snippet shows, do has been repurposed for do-try-catch error handling.
I have a function with the following signature:
static func dictionaryToJSON<K : ToJSON,V : ToJSON> ( dictionary : Dictionary<K,V>) -> JValue
You can find it here.
When I attempt to call this function, I get the error Cannot invoke 'dictionaryToJSON' with an argument list of type '(Dictionary<Domain, Account>)'. Here is the call:
let accounts : JValue = Aeson.dictionaryToJSON( self.accounts)
self.accounts has type Dictionary<Domain,Account>, and Domain and Account both implement the protocol ToJSON. Is there any reason why this doesn't type check? This is for Swift 2 (XCode 7 beta 6), so maybe there is a compiler bug?
It looks like I commented out Domain's implementation of ToJSON to debug and forgot. It's working now.
I was using RAMAnimatedTabBarController Module from here:
https://github.com/Ramotion/animated-tab-bar
I developed my entire application in swift 1.2 using Xcode 6 and the app was running perfectly . I wanted to try out "side loading" of my app using Xcode 7 which has swift 2.0. I had too many errors and I managed to solve most of the errors but three.
1) This line of code which is from that RAMAnimatedTabBarController module is throwing an error saying the function can't be evoked, when this perfectly compiled in Xcode 6:
var constranints = NSLayoutConstraint.constraintsWithVisualFormat(formatString,options:NSLayoutFormatOptions.DirectionRightToLeft,metrics: nil,views: containersDict as [NSObject : AnyObject])
the compiler error for this was:
Cannot invoke 'constraintsWithVisualFormat' with an argument list of
type '(String, options: NSLayoutFormatOptions, metrics: nil, views:
[NSObject : AnyObject])'
2) Another unusual error was thrown:
linker command failed with exit code 1 (use -v to see invocation)
3) And another:
(null): error: cannot parse the debug map for
"/Users/Rakshith/Library/Developer/Xcode/DerivedData/Blubot-heabwwmhqxxvctaabxkwcpgzsadx/Build/Intermediates/SwiftMigration/Blubot/Products/Debug-iphonesimulator/BlubotTests.xctest/BlubotTests":
No such file or directory
What is actually wrong with my project? It is still set to iOS 8.3.
Disable BitCode
Build Settings -> BitCode
I managed to correct the 2nd and 3rd error which most of you probably will face when you're running Xcode 7 Beta as well as Xcode 6.
Just solve these two errors by following the steps mentioned in this tread:
Xcode Version 6.1 (6A1030) - Apple Match O-Linker Error - Building
Try this method:
func createViewContainers() -> [String: UIView] {
var containersDict = [String: UIView]()
guard let tabBarItems = tabBar.items else
{
return containersDict
}
let itemsCount: Int = tabBarItems.count - 1
for index in 0...itemsCount {
let viewContainer = createViewContainer()
containersDict["container\(index)"] = viewContainer
}
var formatString = "H:|-(0)-[container0]"
for index in 1...itemsCount {
formatString += "-(0)-[container\(index)(==container0)]"
}
formatString += "-(0)-|"
let constranints = NSLayoutConstraint.constraintsWithVisualFormat(formatString,
options:NSLayoutFormatOptions.DirectionRightToLeft,
metrics: nil,
views: containersDict)
view.addConstraints(constranints)
return containersDict
}
how about to change the small code from "containersDict as [NSObject : AnyObject]" to "containersDict as [String : AnyObject]".
then I solved the issue above method.
How to solve this error in XQuery. I want the data to be distinct with out duplication in XML result. I tried to add distinct-values in front of the doc in for statement, but this error was depicted.
Engine name: Saxon-PE XQuery 9.5.1.3
Severity: fatal
Description: XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType
Start location: 23:0
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0019
This is code :
for $sv1 in distinct-values(doc('tc.xml')//term/year)
let $sv2 := doc('tc.xml')//term[year= $sv1]
let $sv3 := doc('tc.xml')//student[idStudent= $sv1/idStudent](:HERE IS THE ERROR LINE:)
let $sv4 := doc('tc.xml')//program[idStudent= $sv3/idStudent]
return
<Statistics>
{$sv1 }
<Count_Student>{count($sv2)}</Count_Student>
<a50_60>{count(doc('tc.xml')/mydb//program[doc('tc.xml')/mydb//term/year =$sv1][avg>= 50 and avg < 60])}</a50_60>
</Statistics>
thank you in advance.
distinct-values() will atomize your input, this means that $sv1/idStudent won't work because $sv1 is not an element. Instead of using $sv1 on the line that give an error I think you should be using $sv2.
I have an issue compiling my pebble watchapp. I am trying to send strings to the Pebbl eJS script on the phone lihe this:
Tuplet password_tuple = TupletCString(PASSWORD_KEY, password_str);
Tuplet email_tuple = TupletCString(EMAIL_KEY, email_str);
The compiler error is: (they both error out like this, this is just one of the lines of output below)
./src/app_test.c:84:25: error: the address of 'email_str' will always evaluate as 'true' [-Werror=address]
email_str and password_str are defined at the top of the program, like this:
static char email_str[30];
static char password_str[30];
#define PASSWORD_PKEY (int32_t)21
#define EMAIL_PKEY (int32_t)20
Does anyone notice anything wrong with this?
#ismail-badawi answer is very correct.
Pebble now recommends that you use dict_write_cstring.
dict_write_cstring(&iter, SOME_STRING_KEY, string);
Well it's certainly not obvious, but it turns out it's because TupletCString is a macro, and it'll expand to an expression that contains email_str ? strlen(email_str) + 1 : 0 as a subexpression, and this is what causes the error, because email_str can't be null and so the comparison isn't doing anything.
I found this thread on the Pebble forums with an explanation. The suggested fix is to define your own macro that doesn't have a conditional, e.g.
#define MyTupletCString(_key, _cstring) \
((const Tuplet) { .type = TUPLE_CSTRING, .key = _key, .cstring = { .data = _cstring, .length = strlen(_cstring) + 1 }})