Xcode beta 7 - Do-While loop SWIFT Error - xcode

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.

Related

Recursion and Xcode 7 compile error

this is a simple recursion function
func recursion(parameter : Double)
{
if parameter < 12
{
recursion(parameter + 1)
}
print(parameter)
}
when i am trying to put a simple value for example 0 or 1
recursion(0)
i get a compile error saying Missing argument for #1 in call any idea why this is happening?
btw if i change the function to
func recursion(parameter : Double)
{
if parameter > 1
{
recursion(parameter - 1)
}
print(parameter)
}
everything works fine
any ideas? i am using Xcode 7 beta
Your code works fine, just make a Clean & Build and then try it again and the initial compile error should disappear. Remember that Xcode 7 is still in Beta, Apple is working to fix this kind of false compile errors properly.
I hope this help you.

Compilation error in Release in Xcode 7 beta 5 in Swift code

I have the following code.
class MyClass {
private var callbacks: [()->()] = []
func doIt(callback: (()->())?) {
if let callback = callback {
callbacks.append(callback)
}
// ... other code here
}
}
When I build the project in Release it shows the following error:
Command failed due to signal: Abort trap: 6
Assertion failed: (PAI2->use_empty() && "Should not have any uses"), function foldInverseReabstractionThunks, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.52.2/src/swift/lib/SILPasses/SILCombinerVisitors.cpp, line 549.
While running SILFunctionTransform "SIL Combine" on SILFunction "#TFC11AddCallback7MyClass4doItfS0_FGSqFT_T__T".
Note that the error appears only in Release and only in Xcode 7 beta 5. The code worked in Xcode 7 beta 4.
Demo: https://github.com/exchangegroup/add-callback-demo-ios
Looks like a bug in Swift? Submitted a bug report to Apple.
Update
The issue has been resolved in Xcode 7.0 beta 6 (7A192o).
I was having this same problem (beta 5 only).
It was where I was trying to append a closure to an array of closures, it looks to be the same for yours where you have an addCallback method in your MyClass class.
As silly as it is, I got mine to build on release from changing this code:
callbacks.append(newCallback)
to this
callbacks = callbacks + [newCallback]

Swift 2.0, Xcode 7 issue

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.

can not make xpath with functions work with JDOM2

I used JDOM1 before to parse xmls with xpath, and tired with the non-generic style, so I decide to try JDOM2, OK, everything works perfect for me ( the generic, XPathFactory, XPathExpression). then I try a xpath statement with contains function :
XPathExpression<Text> timeXpath = XPathFactory.instance().compile(
"./p[contains(.,'time:')]/text()", Filters.textOnly());
String time = timeXpath.evaluateFirst(div).getTextTrim();
then I got exeptions:
java.lang.IllegalStateException: Unable to evaluate expression. See cause
at org.jdom2.xpath.jaxen.JaxenCompiled.evaluateRawFirst(JaxenCompiled.java:200)
at org.jdom2.xpath.util.AbstractXPathCompiled.evaluateFirst(AbstractXPathCompiled.java:327)
at peace.org.tm.spider.star.DamaiStarSpider.syncStarTracks(DamaiStarSpider.java:123)
at peace.org.tm.spider.star.DamaiStarSpider.main(DamaiStarSpider.java:156)
Caused by: org.jaxen.UnresolvableException: Function :contains
at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:142)
at org.jaxen.ContextSupport.getFunction(ContextSupport.java:189)
at org.jaxen.Context.getFunction(Context.java:153)
at org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:183)
at org.jaxen.expr.DefaultPredicate.evaluate(DefaultPredicate.java:106)
at org.jaxen.expr.PredicateSet.evaluatePredicates(PredicateSet.java:188)
at org.jaxen.expr.DefaultLocationPath.evaluate(DefaultLocationPath.java:218)
then I tried:
XPathExpression<Text> timeXpath = XPathFactory.instance().compile(
"./p[fn:contains(.,'time:')]/text()", Filters.textOnly());
String time = timeXpath.evaluateFirst(div).getTextTrim();
xpath compile failed:
java.lang.IllegalArgumentException: Unable to compile './p[fn:contains(.,'time:')]/text()'. See Cause.
at org.jdom2.xpath.jaxen.JaxenCompiled.<init>(JaxenCompiled.java:152)
at org.jdom2.xpath.jaxen.JaxenXPathFactory.compile(JaxenXPathFactory.java:82)
at org.jdom2.xpath.XPathFactory.compile(XPathFactory.java:282)
at peace.org.tm.spider.star.DamaiStarSpider.syncStarTracks(DamaiStarSpider.java:91)
at peace.org.tm.spider.star.DamaiStarSpider.main(DamaiStarSpider.java:156)
Caused by: org.jaxen.XPathSyntaxException: Unexpected '('
at org.jaxen.BaseXPath.<init>(BaseXPath.java:136)
at org.jaxen.BaseXPath.<init>(BaseXPath.java:157)
at org.jdom2.xpath.jaxen.JaxenCompiled.<init>(JaxenCompiled.java:150)
... 4 more
I already google the stack trace for about 2 hours, nothing useful founded, I think maybe I made a very stupid mistake, is anyone can figure it out for me? thanks!
I can't reproduce the exceptions you are getting.... I am using JDOM 2.0.5 with Jaxen 1.1.6.
I have created the following:
public static void main(String[] args) {
Element root = new Element ("root");
Element p = new Element("p");
p.addContent(" Return this time: Boo! ");
root.addContent(p);
XPathExpression<Text> timeXpath = XPathFactory.instance().compile(
"./p[contains(.,'time:')]/text()", Filters.textOnly());
XPathDiagnostic<Text> xpd = timeXpath.diagnose(root, true);
System.out.println(xpd);
System.out.println(timeXpath.evaluateFirst(root).getTextTrim());
}
and it produces:
[XPathDiagnostic: './p[contains(.,'time:')]/text()' evaluated (first) against org.jdom2.Element produced raw=1 discarded=0 returned=1]
Return this time: Boo!
I believe you may have out-of-date Jaxen class libraries?

Xcode 4.6 if statement with &&

My problem is
-(IBAction)setAction:(id)sender{
if ([labelOne.text isEqual: #"One"] && [labelTwo.text isEqual: #"Two"]) {
labelShow.text = #"Yes it works :)";
}
}
And if i build it. It show me the error code: Thread 1: signal SIGBART
but it works if i do it like this
-(IBAction)setAction:(id)sender{
if ([labelOne.text isEqual: #"One"]) {
labelShow.text = #"Yes it works :)";
}
}
What can I do, that the First one works?:)
The SIBABRT implies that either labelTwo or labelTwo.text is pointing to bad memory.
First figure out which pointer is bad, and then debug to see why. Also, provide a crash log when possible. There should be an error message associated in your debug output pane.
Check out this debugging tutorial.

Resources