ios


Crash when accessing nested completion block — EXC_BAD_ACCESS


I've found a reliable crash with EXC_BAD_ACCESS while implementing a cache on my app. I've recreated the situation in a new project in about ~50 lines of code with 2 pods (Alamofire, HanekeSwift), and it crashes every time.
All I am doing is in my ViewController, calling a cache get:
CachingManager.sharedInstance.fetchAllThings({
result in
// result should be an array of objects
print(result)
})
and the CachingManager's fetchAllThings method is:
func fetchAllThings(completion: ([AnyObject] -> Void)?) {
let fetcher = CustomFetcher<JSON>(key: "HELLO")
fetcher.fetch(failure: {
error in
print(error)
}, success: {
json in
completion?(json.array)
})
}
Now, the CustomFetcher found above is implemented as such:
override func fetch(failure fail: ((NSError?) -> ()), success succeed: (JSON) -> ()) {
let endpoint = "www.google.com"
Alamofire.request(.GET, endpoint, parameters: nil, encoding: .URL, headers: nil)
.responseJSON {
(data) -> Void in
self.onReceiveData(data.data!, failure: fail, success: succeed)
}
}
private func onReceiveData(data: NSData, failure: ((NSError?) -> ()), success: (JSON) -> ()) {
success(JSON.Array(["HI"])) <--- CRASH HAPPENS HERE
}
I get an EXC_BAD_ACCESS when trying to run the success block in my onReceiveData.
Am I doing something wrong? Is this a Swift issue? Is this an issue with the pods I'm using?
For reference, linked is a project with the code above that will crash on launch every time if that helps anyone debug this.
Project on GitHub
Seems like the use of a Custom fetcher is not that clear in the Haneke docs. With the above fetchAllThings method, I was trying to fetch directly from the CustomFetcher, which was causing the bad access (that is not it's intended use, I am guessing). The correct way to use a fetcher with a JSON cache is:
func fetchAllThings(completion: ([AnyObject] -> Void)?) {
let fetcher = CustomFetcher<JSON>(key: "HELLO")
let cache = Shared.JSONCache
cache.fetch(fetcher: fetcher, formatName: "original", failure: {
error in
print(error)
}, success: {
json in
completion?(json.array)
})
}
The key here is that I am now using the library's cache object to invoke the Fetcher.
I hope this helps someone!

Related Links

Linker command failed, cannot find library in existing project
Stop all the functions when changing Viewcontroller
iOS & Parse Push Notification - iPhone 5s/c
Flick a UIScrollView programmatically
Negative Error testing in iOS PayPal Sandbox mode
why i have this showAlert error?
Issue in sending email from iOS device?
iPad crash with Foundation
Reorder Uitableview with Parse Objects?
Running Xamarin.iOS tabbed application in VS2015
How to change presentViewController Transition animation
Overriding 'finished' in asynchronous NSOperation
Change parameter inside dispatch_async from main thread
fb ios sdk 4.5 crashes in iOS7
How to get last frame from video?
Share content on an iOS native app via messages or email with long enough trial

Categories

HOME
graph
oozie
google-search
codenameone
robot
openvpn
sony
pyusb
http2
prestashop-1.7
square-connect
pie-chart
sql-server-express
imp
partitioning
android-dialogfragment
jmespath
snort
swig
spark-graphx
mediator
italic
weather-api
pdfa
android-security
plm
azure-api-apps
photo-gallery
html-select
titanium-alloy
weebly
psychopy
angularjs-routing
move
gcc4.8
canopen
dwr
python-module
omniauth
email-notifications
kombu
surroundscm
ellipsis
telecommunication
android-location
mongolab
jquery-load
xlform
docklight
jedi
python-dragonfly
database-tuning-advisor
nominatim
spymemcached
mtp
heroku-toolbelt
nbug
realm-list
translate3d
error-log
data-science-studio
targetinvocationexception
lossless-compression
iscroll4
servlet-listeners
sbrk
formhelper
iqueryable
first-class-functions
deepzoom
magic-unipaas
requiredfieldvalidator
pligg
flash-cs4
nsimageview
gigaspaces
file-structure
harvest
zmodem
xml-dtd
ria
adaboost
j#
junitperf
retain
eye-detection
having
formsauthentication
orthographic
jdic
apache-config
remote-control
chickenfoot
database-dump
case-tools

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App