Eureka forms gives error EXC_BAD_INSTRUCTION INVOP - eureka-forms

I have just started using Eureka Forms in my Swift 3 project.
I have created my first form with a TextRow that looks like this:
<<< TextRow() {
$0.tag = tagname
$0.title = title
$0.placeholder = placeholder
}
It displays correctly on the simulator, however when I click in the field I immediately get a crash:
EXC_BAD_INSTRUCTION (code =EXC_1386,INVOP,subcode=0x0)
On the guard line (from the Eureka framework):
private func displayValue(useFormatter: Bool) -> String? {
guard let v = row.value else { return nil }
It must be something simple, can anybody point me in the right direction please?

That error seems to say that the row.value is needed, so maybe you can add an initial value ("") in the init callback. It may be an old or unreleased commit. Please try the latest version or see if the version you used has that particular bug.

Related

Converting AppleScript to SwiftAutomation

This AppleScript that I found here does what I want:
tell application "iTunes"
set matchtrack to tracks in playlist 1 whose persistent ID is "C70EA9CDC276CB6D"
if matchtrack is not {} then
return name of item 1 of matchtrack
else
return "no track found"
end if
end tell
That is, finds a track based on the persistent ID. I'm trying to get it to work in a MacOS Cocoa Swift application using the Swift Automation as an Apple Event Bridge. I can retrieve the value with:
let trackID = try iTunes.tracks[1].persistentID.get()
I've tried all sorts of statements. This one seems to show the most promise:
let trackRow = try iTunes.tracks[ITUItem.persistentID == "C70EA9CDC276CB6D"].get() as ITUItem
When I run it, I get the error:
Instance member 'persistentID' cannot be used on type 'ITUItem'
The framework is in beta at the best so it may be a bug. Any suggestions on what else to try? I'd ask the author, but I can't find a way to contact him.
Here is part of the sdef file that was generated by the app.
item n : an item
properties
class_ (type, r/o) : the class of the item
container (specifier, r/o) : the container of the item
id (integer, r/o) : the id of the item
index (integer, r/o) : The index of the item in internal application order.
name (text) : the name of the item
persistentID (text, r/o) : the id of the item as a hexadecimal string. This id does not change over time.
properties (record) : every property of the item
Track is a subclass of item.
Fix
When I first tried #matt's suggestion of ITUIts.persistentID, it wouldn't compile. I got the error:
Binary operator '==' cannot be applied to operands of type 'ITUItem' and 'String'
After some back and forth, I realized the problem was that I was missing an import:
import SwiftAutomation
I had it in originally and wasn't sure I needed it so I commented it out. A dozen other calls to it worked fine without it before I got to this one.
Use ITUIts and get rid of as ITUItem. So:
let trackRow = try itunes.tracks[ITUIts.persistentID == "C70EA9CDC276CB6D"].get()
// result will be something along these lines:
// [ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)]
Herewith, a complete working test along with the results on my machine (of course your numbers will be different):
let itunes = ITunes()
let trackID = try itunes.tracks[1].persistentID.get() as String
print("track ID is", trackID)
// track ID is 689006177BB39343
let trackRows = try itunes.tracks[ITUIts.persistentID == trackID].get() as [ITUItem]
if let trackRow = trackRows.first {
print(trackRow)
// ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)
}

String indices in Swift 2

I decided to learn Swift and I decided to start with Swift 2 right away.
So here is a very basic example that's similar to one of the examples from Apple's own e-book about Swift
let greeting = "Guten Tag"
for index in indices(greeting) {
print(greeting[index])
}
I tried this in the playground of Xcode 7 and I received the following error
Cannot invoke 'indices' with an argument list of type '(String)'
I also tried the same thing with Xcode 6 (which is Swift 1.2 AFAIK) and it worked as expected.
Now, my question is: Is this
An error in Xcode 7, it's still a beta release after all, or
Something that just doesn't work anymore with Swift 2 and the e-book just isn't fully updated yet?
Also: If the answer is "2", how would you replace indices(String) in Swift 2?
In a Playground, if you go to menu View > Debug Area > Show debug area, you can see the full error in the console:
/var/folders/2q/1tmskxd92m94__097w5kgxbr0000gn/T/./lldb/94138/playground29.swift:5:14: error: 'indices' is unavailable: access the 'indices' property on the collection
for index in indices(greeting)
Also, Strings do not conform to SequenceTypes anymore, but you can access their elements by calling characters.
So the solution for Swift 2 is to do it like this:
let greeting = "Guten Tag"
for index in greeting.characters.indices {
print(greeting[index])
}
Result:
G
u
t
e
n
T
a
g
Of course, I assume your example is just to test indices, but otherwise you could just do:
for letter in greeting.characters {
print(letter)
}
Just for completion, I have found a very simple way to get characters and substrings out of strings (this is not my code, but I can't remember where I got it from):
include this String extension in your project:
extension String {
subscript (i: Int) -> Character {
return self[self.startIndex.advancedBy(i)]
}
subscript (i: Int) -> String {
return String(self[i] as Character)
}
subscript (r: Range<Int>) -> String {
return substringWithRange(Range(start: startIndex.advancedBy(r.startIndex), end: startIndex.advancedBy(r.endIndex)))
}
}
this will enable you to do:
print("myTest"[3]) //the result is "e"
print("myTest"[1...3]) //the result is "yTe"
Here is the code that you looking:
var middleName :String? = "some thing"
for index in (middleName?.characters.indices)! {
// do some thing with index
}

ABRecordCopyValue not working when object doesn't exist

This line of code in Swift causes me problems when the address book has a contact with no last name.
I've tried to resolve it a number of ways to no avail. Is there some sort of try catch statement or error handling I can use? Or check if AnyObject is null (the return type of
ABRecordCopyValue(person, kABPersonLastNameProperty).takeRetainedValue()).
I've tried using optional types but it doesn't seem to work since the app stops running the moment you select a contact with no last name - and the line of code below gets highlighted with the error Thread
1: EXC_BAD_ACCESS
let lName = ABRecordCopyValue(person, kABPersonLastNameProperty).takeRetainedValue() as String
ABRecordCopyValue can actually return nil so you should unwrap it. Also, casting to String didn't work for me so I'm using NSString.
if let firstName = ABRecordCopyValue(abContact, kABPersonFirstNameProperty)?.takeRetainedValue() as? NSString {
println("FIRST NAME: \(firstName)")
}
else {
println("No Name")
}
Another thing you could try is instead of getting the first and lastName individually, you could also try to get the composed name.
if let fullName = ABRecordCopyCompositeName(abContact)?.takeRetainedValue() as String? {
println("Full Name: \(fullName)")
}
P.S: I've also tried all the answers from this question but despite of making perfect sense and working when debugging the app, they crashed when I deployed the archive directly into the phone.

Are breakpoints not working as they should in DartEditor?

I'm getting some unexpected behaviour in the most recent Dart editor (version 0.4.0_r18915).
I have this minimal command line app that was intended to either take a command line argument or not and print a hello -somenoe- message. The application works just fine. But the debuggins fails to stop at the breakpoints set inside each of the if statement bodies. (I wanted to look at the state of the application weather the options.arguments.isEmpty was true or false)
var person;
main(){
var options = new Options();
if(options.arguments.isEmpty){
person = "someone who forgot to pass a command-line argument";
} else {
person = options.arguments[0];
}
print("Hello, $person!");
}
Debugger will stop at breakpoints in other lines but not in:
person = "someone who forgot to pass a command-line argument";
or in:
person = options.arguments[0];
Yes, file a bug. My suspicion is that the debugger can only stop at what's called a "safepoint" and that the assignment of a constant to a variable doesn't create one. Adding some line above it, like
print("breakpoint");
should help if that's the case. But I've also seen other problems with breakpoints not firing.

Filter Too Quickly issue

In ExtJS 4.1.3 we have a filter setup on a text field to run 'onchange' of the text field. This is the function onchange:
var store = this.getStore();
value = field.getValue();
if (value.length > 0) {
// Param name is ignored here since we use custom encoding in the proxy.
// id is used by the Store to replace any previous filter
store.filter({
id: 'query',
property: 'query',
value: 'LegalName|#|#|' + value
});
} else {
store.clearFilter();
}
Now, we are running into an issue where when I type something in the text field too fast I am getting errors and am getting stuck on a load screen. When I type in the same thing slowly it works. Considering typing it in slowly makes it work, but fast makes it fail and the data coming back from the server is the same in both instances, I'm assuming it's an issue with ExtJS. Has anyone seen an issue like this? What are potential problems and fixes. I can't figure out why it's breaking. Here is the trail I get:
Uncaught TypeError: Cannot convert null to object ext-all-debug.js:51752
Ext.define.cancelAllPrefetches ext-all-debug.js:51752
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.define.clear ext-all-debug.js:44718
Base.implement.callParent ext-all-debug.js:3735
Ext.define.clear ext-all-debug.js:47485
Base.implement.callParent ext-all-debug.js:3735
PageMap.Ext.Class.clear ext-all-debug.js:52358
Ext.define.filter ext-all-debug.js:51377
Ext.define.onTextfieldChange /TEST/app/view/ContractGrid.js?_dc=1354553533935:447
Ext.util.Event.Ext.extend.fire ext-all-debug.js:8638
Ext.define.continueFireEvent ext-all-debug.js:25117
Ext.define.fireEvent ext-all-debug.js:25095
Ext.override.fireEvent ext-all-debug.js:58382
Ext.define.checkChange ext-all-debug.js:30310
call ext-all-debug.js:8426
Any thoughts?
I was able to fix the issue by changing the buffer setting on the store. Looks like I had set 'buffered' to true in the store and once I removed it, the issue went away.

Resources