I am trying to create an app similar to the Reactable.
The user will be able to drag "modules" like an oscillator or filter from a menu into the "play area" and the module will be activated.
I am thinking to initialize the modules as they intersect with the "play area" background object. However, this requires me to name the modules automatically, i.e.:
let osci = AKOscillator()
where osci will automatically count up to be:
let osci1 = AKOscillator()
let osci2 = AKOscillator()
...
etc.
How will I be able to do this?
Thanks
edit: I am trying to use an array by creating an array of
var osciArray = [AKOscillator]()
and in my function to add an oscillator, this is my code:
let oscis = AKOscillator()
osciArray.append(oscis)
osciArray[oscCounter].frequency = freqValue
osciArray[oscCounter].amplitude = 0.5
osciArray[oscCounter].start()
selectedNode.userData = ["counter": oscCounter]
oscCounter += 1
currentOutput = osciArray[oscCounter]
AudioKit.output = currentOutput
AudioKit.start()
My app builds fine, but once the app starts running on the Simulator I get error : fatal error: Index out of range
I haven't used AudioKit, but I read about it a while ago and I have quite a big interest in it. From what I understand from the documentation, it's structured pretty much like SpriteKit: nodes connected together.
I guess then that most classes in the library derive from a base class, just like everything in SpriteKit derives from the SKNode class.
Since you are linking the audio kit nodes with visual representations via SpriteKit nodes, why don't you simply subclass from an SKSpriteNode and add an optional audioNode property with the base class from AudioKit?
That way you can just use SpriteKit to interact directly with the stored audio node property.
I think there's a lot of AudioKit related code in your question, but to answer the question, you only have to look at oscCounter. You don't show its initial value, but I am guessing it was zero. Then you increment it by 1 and try to access osciArray[oscCounter] which has only one element so it should be accessed by osciArray[0]. Move the counter lower and you'll be better off. Furthermore, your oscillators look like local variables, so they'll get lost once the scope is lost. They should be declared as instance variables in your class or whatever this is part of.
I would like to download multiple offline map databases using MBXMapKit. This is more a Objective-C problem than a MBXMapKit library problem.
I would like to do something like this:
for ( DestinationObject *dest in self.dest ) {
//Put the map to the right position
[self centerMapWithDest:dest];
[[MBXOfflineMapDownloader sharedOfflineMapDownloader] beginDownloadingMapID:_rasterOverlay.mapID mapRegion:_mapView.region minimumZ:_rasterOverlay.minimumZ maximumZ:MIN(16,_rasterOverlay.maximumZ)];
}
and here the delegate function:
-(void)offlineMapDownloader:(MBXOfflineMapDownloader *)offlineMapDownloader didCompleteOfflineMapDatabase:
I know this is not possible like this because the library crashes after the second call because the first part is not finished yet.
But how to call the next download when the first one is finished ?
Thanks in advance
Per the documentation, you want to use the MBXOfflineMapDownloaderDelegate protocol to know when a download completes/fails out before starting the next one, since the downloaded class can only handle one download at a time.
I'm trying to "mimic" the BusinessLayer functionality by creating a CEMarkerGroup for my own markers, then setting the following:
CEMarkerGroup *myGroup = [self.mapView markerGroupWithName:#"myMarkers"];
[myGroup setShouldTestForCollisions:YES];
And then, according to the Citymaps' current documentation, I try to set individual collisionPriority values to each like this:
[marker setCollisionPriority:25.0f]; //<-- ERROR!!, or
marker.collisionPriority = 25.0f; //<-- same ERROR
[myGroup addMarker:marker];
Error is: No visible #interface for 'CEMarker' declares the selector 'setCollisionPriority:'
As my goal is to approximate Citymaps' very slick behavior of avoiding marker overlaps, does anyone know of a workaround for this issue, or perhaps another approach altogether? Much thanks!
I am a developer at Citymaps. Thank you for your interest in our SDK!
Our documentation got a bit ahead of itself. Turns out, we never exposed the collisionPriority property. I've given myself a ticket to do so, and will let you know immediately when a new build is out containing this change.
Is it just me or Xcode 6 (6.0.1) with Swift seems to be super slow when you type your code, especially with autocompletion?
A normal Objective-C class, even if inside a Swift project, works almost the same as before, so it's Swift that kills it.
Does anyone else experience the same inconvenience? Do you have any idea of how to improve performance?
I tried to play with some settings but no luck.
I've also of course tried restarting Xcode and the computer with no luck.
No other heavy
apps are open.
I use a Mid 2009 Macbook Pro (2.26 GHz Intel Core 2 Duo) with 8GB RAM and SSD HD, which is not the newest thing at all, but still not a complete junk.
It is a shame as I was excited to start using Swift and it is now really unbearable.
Thoughts / tips?
Quit Xcode and restart the Mac are not required but preferred.
Delete the content of the folder
~/Library/Developer/Xcode/DerivedData
Delete the content ~/Library/Caches/com.apple.dt.Xcode
This is a temporally solution, but works greatly.
Below the script using Script Editor app.
tell application "Terminal"
do script "rm -frd ~/Library/Developer/Xcode/DerivedData/*"
do script "rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
end tell
Alternatively, you can create an alias for your terminal like this:
alias xcodeclean="rm -frd ~/Library/Developer/Xcode/DerivedData/* && rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
You can add that to your ~/.bash_profile and then type xcodeclean on the command line every time you would like to clear those two folders.
I also experienced 100%+ CPU while typing some "simple" code. Some small tricks to make the swift-parser quicker by the way you structure your code.
Don't use the "+" concatinator in strings. For me this triggers the slowness very quickly.
Each new "+" brings the parser to a crawl, and it has to reparse the code everytime you add a new char somewhere in your function body.
Instead of:
var str = "This" + String(myArray.count) + " is " + String(someVar)
Use the template-syntax which seems much more efficient to parse in swift:
var str = "This \(myArray.count) is \(someVar)"
This way i basically notice no limit in strlen with inline vars "\(*)" .
If you have calculations, which use + / * - then split them into smaller parts.
Instead of:
var result = pi * 2 * radius
use:
var result = pi * 2
result *= radius
It might look less efficient, but the swift parser is much faster this way.
Some formulas won't compile, if they have to many operations, even if they are mathematically correct.
If you have some complex calculations then put it in a func. This way the parser can parse it once and does not have to reparse it everytime you change something in your function body.
Because if you have a calculation in your function body then somehow the swift parser checks it everytime if the types, syntax etc. are still correct. If a line changes above the calculation, then some vars inside your calculation / formula might have changed. If you put it in an external function then it will be validated once and swift is happy that it will be correct and does not reparse it constantly, which is causing the high CPU usage.
This way i got from 100% on each keypress to low CPU while typing.
For example this 3 lines put inline in your function body can bring the swiftparser to a crawl.
let fullPath = "\(NSHomeDirectory())/Library/Preferences/com.apple.spaces.plist"
let spacesData = NSDictionary(contentsOfFile: fullPath )! // as Dictionary<String, AnyObject>
let spaces : AnyObject = spacesData["SpacesDisplayConfiguration"]!["Management Data"]!!["Monitors"]!![0]["Spaces"]!!
println ( spaces )
but if i put it in a func and call it later , swiftparser is much quicker
// some crazy typecasting here to silence the parser
// Autodetect of Type from Plist is very rudimentary,
// so you have to teach swift your types
// i hope this will get improved in swift in future
// would be much easier if one had a xpath filter with
// spacesData.getxpath( "SpacesDisplayConfiguration/Management Data/Monitors/0/Spaces" ) as Array<*>
// and xcode could detect type from the plist automatically
// maybe somebody can show me a more efficient way to do it
// again to make it nice for the swift parser, many vars and small statements
func getSpacesDataFromPlist() -> Array<Dictionary<String, AnyObject>> {
let fullPath = "\(NSHomeDirectory())/Library/Preferences/com.apple.spaces.plist"
let spacesData = NSDictionary(contentsOfFile: fullPath )! as Dictionary<String, AnyObject>
let sdconfig = spacesData["SpacesDisplayConfiguration"] as Dictionary<String, AnyObject>
let mandata = sdconfig["Management Data"] as Dictionary<String, AnyObject>
let monitors = mandata["Monitors"] as Array<Dictionary<String, AnyObject>>
let monitor = monitors[0] as Dictionary<String, AnyObject>
let spaces = monitor["Spaces"] as Array<Dictionary<String, AnyObject>>
return spaces
}
func awakeFromNib() {
....
... typing here ...
let spaces = self.getSpacesDataFromPlist()
println( spaces)
}
Swift and XCode 6.1 is still very buggy, but if you follow these simple tricks, editing code becomes acceptable again. I prefer swift a lot, as it gets rid of .h files and uses much cleaner syntax. There is still many type-casting needed like "myVar as AnyObject" , but thats the smaller evil compared to complex objective-c project structure and syntax.
Also another experience, i tried the SpriteKit, which is fun to use, but its quite in-efficient if you don't need a constant repaint at 60fps. Using old CALayers is much better for the CPU if your "sprites" don't change that often. If you don't change the .contents of the layers then CPU is basically idle, but if you have a SpriteKit app running in background, then videoplayback in other apps might start to stutter due to the hardlimited 60fps update-loop.
Sometimes xcode shows odd errors while compiling, then it helps to go into menu "Product > Clean" and compile it again, seems to be a buggy implementation of the cache.
Another great way to improve parsing when xcode gets stuck with your code is mentioned in another stackoverflow post here. Basically you copy all contents from your .swift file into an external editor, and then function by function copy it back and see where your bottleneck is. This actually helped me to get xcode to a reasonable speed again, after my project went crazy with 100% CPU. while copying your code back, you can refactor it and try to keep your function-bodies short and functions/formulars/expressions simple (or split in several lines).
Autocomplete is broken since Xcode 4. Until Apple decides to fix this 2 years old bug, the only solution, unfortunately, is to turn code completion OFF on XCode's preferences (first option of the pic below).
You can continue to enjoy completion manually by typing CTRL space or ESC when you need it.
This is the only solution that works every time for 100% of the cases.
Another thing I have discovered recently is: if you use plugins on Xcode, don't. Remove them all. They make the problem worse.
Are you using Spotify?
I installed Yosemite GM with Xcode 6.1 GM on an iMac mid 2009 (2.66Ghz) having the same problem.I found that a process called "SpotifyWebHelper" is always marked red as not responding, so i disabled the option "start from web" in spotify and now Xcode seem to run significantly better.
I found out that usually happens when you:
have long expressions in a single statement (see this answer)
mix multiple custom operators in a single expression
The 2nd case seems to be fixed in one of the latest xcode releases. Example: I defined 2 custom operators <&&> and <||>, and used in an expression like a <&&> b <&&> c <||> d. Splitting to multiple lines solved the problem:
let r1 = a <&&> b
let r2 = r1 <&&> c
let r3 = r2 <||> d
I hope that your cases is covered by one of the 2 above... please post a comment either case
I had the same issues even in Xcode 6.3
super slow autocompletions
super slow indexing
enormous CPU usage by swift and SourceKitService
enormous Memory usage by SourceKitService
All this was happening even in relatively small project. I tried all the fixes I could find:
deleting ~/Library/Developer/Xcode/DerivedData/*
deleting ~/Library/Caches/com.apple.dt.Xcode/*
remove all "+" String combining from the code
removed all suspicious dictionary declarations
None of these actually helped in my project.
What actually solved my problem was:
placing each end every class in its own file
placing each and every extension in its own file (Class+ExtName.swift)
placing "out of class swift methods" in its own file
Now I have close to zero CPU usage, low memory usage, and decently fast completions.
Generally, moving the cache folder (DerivedData) to a SSD drive (specifically in my case - an outer storage connected to thunderbolt exit) has dramatically improved my Xcode performance.. Compilation time and general wondering around the app is about 10 time faster.. Also moved the whole git folder to the SSD, which dramatically improved git performance.
It was a pain until XCode 7.2.
Apple fixed it in XCode 7.3 and now it works like a charm. It's super fast and much more powerful as it seems to work a bit like the fuzzy search of files : you don't have to actually type the exact beginning of the method/property for it to appear in the list of propositions.
Collapsing all methods helps a little.
command-alt-shift-left arrow will do the trick...
To fold/unfold current methods or if structures use:
Fold: command-alt-left arrow
Unfold: command-alt-right arrow
SourceKitService is also kinda clumsy to deal with comments in the code and the embedded comments slow it down too.
so if you can afford to remove the massive blob of embedded comments like this:
/*
* comment
/*
* embedded comment
*/
*/
that can definitely help as well.
NOTE: in my case my Xcode 7.3.1 (7D1014) was literally blocked me typing any letter when the file had about 700 lines of comment with embedded comments. initially I removed that block from that .swift file and Xcode has become alive again. I tried added my comments back part by part by removing embedded comments, it was still slower than usual but it shown significantly better performance if there were no embedded comments.
I had the same issue where typing was lagging in a particular class and turns out that
/*
Long
multiline
comments
*/
was slowing down the typing.
I'm using Instruments for iOS automation and I can't seem to figure out how to tap options on the copy/paste menu. When I do a logElementTree(),I see that we are returning a UIEditingMenu and then three elements (which correspond to options of that menu, such as copy/paste, etc..). I am attempting to place this into a variable, and then trying to "tap" that variable but I cannot get that to work. Here is a sample of my code:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
//This generates the highlighted text
app.dragInsideWithOptions({startOffset:{x:0.45, y:0.6}, endOffset:{x:0.45, y:0.6}, duration:1.5});
var copy = app.editingMenu.elements.withName("copyButton");
copy.tap();
Instruments returns, "0) UIAElementNil". In addition to the above, I've also tried:
app.elements.withName("copyButton")
window.elements.withName("copyButton")
So, I can get the editingMenu to produce the available options, but I cannot figure out a way to tap or select one of those options. I'm not quite sure I know how to reference those options to begin with.
Does anyone have any ideas?
Thanks!
You should try app.editingMenu().elements()[index].tap() where index is the index of the option you want to tap from the array of elements returned. I got my one working this way.
Hey.
First of all, I was always using .elements() not .elements... but it is JS, so it may be invoking function that is assigned to object property..?
Anyway, maybe this edit menu is not internal window of the app, but it is system level menu, that is invoked, when you do the drag? If that is true, try:
UIATarget.localTarget().frontMostApp().elements().withName("copyButton").tap();
But as I see in apple reference your version with calling app.editingMenu() should be fine...
Maybe try calling buttons by position, and you will see which respond:
UIATarget.localTarget().frontMostApp().editingMenu().elements()[0].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[1].tap;
UIATarget.localTarget().frontMostApp().editingMenu().elements()[2].tap;
You should find position of correct one this way. When you have it's position you can check its properties by button.logElement();. With this inf you you should be able to switch back to .withName method instead hardcoded position.
I did this similar to yoosiba but with editingMenu element names.
Using Xcode 4.5.1 and device running iOS 6.
Using Alex Vollmer's excellent tuneup_js for target, app and vtap().
Otherwise you can use UIATarget.localTarget().frontMostApp() and tap().
NOTE: vtap() will delay and retry tapping. Without this you may need to add your own delays.
// tap in textFieldA to see editingMenu.
app.mainWindow().textFields()["textFieldA"].vtap();
app.editingMenu().elements()["Select All"].vtap();
app.editingMenu().elements()["Copy"].vtap();
// must delay before attempting next tap
target.delay(2);
// ... navigate to different section of the app
// tap in textFieldB to see editingMenu.
app.mainWindow().textFields()["textFieldB"].vtap();
// paste clipboard contents copied from textFieldA into textFieldB
app.editingMenu().elements()["Paste"].vtap();
target.delay(2);