objective-c,ios,cocoa,osxRelated issues-Collection of common programming errors
Guy
iphone objective-c ios image-processing
I’m trying to combine two photos into one image (think a body with a hole in the face on top of a picture of a different person’s face). The top image has some semi-transparent pixels and some fully transparent pixels and I want to overlay it on top of a solid image.Here’s what I’m doing: I have a Context with the right size and I draw the bottom image on it, without any alpha (faceImage). On top of that I draw an image that has a transparent hole in it, with various levels of transparencies (co
Dov
objective-c cocoa unit-testing key-value-observing ocmock
I would like to test that Key-Value-Observation is working properly for a class of mine. It has one property, which depends on another. They are set up like so:+ (NSSet *)keyPathsForValuesAffectingSecondProperty {return [NSSet setWithObjects:@”firstProperty”,nil]; }- (NSArray *)secondProperty {return [self.firstProperty array]; }I want to run a unit test to verify that when firstProperty changes, an object bound to secondProperty gets a notification. At first I thought I would be able to use +[O
danielpunkass
ios objective-c osx cocoa automatic-ref-counting
In Apple’s documentation about ARC, they make a point of spelling out a problematic scenario in which ARC will generate a boilerplate temporary variable behind the scenes. Search on “The compiler therefore rewrites”:https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.htmlThe gist of the warning seems to be that because the stack-based variable is “strong” and the by-reference parameter to the called method (performOperationWithError:) i
SaamJB
iphone objective-c ios
I have a UITableViewController that when a cell is pressed, I want the controller to pop itself, and then have the controller it pop’s to, push another view controller onto the stack.I am invoking this method because the popped-to viewController is the delegate of the tableViewControllerI am currently invoking this method with a delay on it, because otherwise, everything gets screwed up waiting for the animation to end. Doing it this way seems a bit hacky and seems to me like it would fail if so
Steven
objective-c ios oauth
I’ve been trying to get a basic OAuth interaction working without success. There are certainly similar questions already posed on SO, but most of them have no replies. I’m getting pretty desperate here, so I’m just going to start by posting my entire code:// OAuth parameters NSString *oauthNonce = [self genRandStringLength:20]; NSString *oauthSignatureMethod = [NSString stringWithFormat:@”HMAC-SHA1″]; time_t oauthTimeStamp = (time_t) [[NSDate date] timeIntervalSince1970];// generate OAuth signat
morgancodes
objective-c cocoa cocoa-touch json
In java-land, there are a handful of useful libraries which will convert json strings to objects of matching type. The json libraries I’ve seen for cocoa simply create nested NSDictionaries and NSArrays. Is there a tool out there which will go the extra step of reconstituting whatever object type I want? So, for example, if I have a class called “Unicorn”, with a property “maneColor”, and I have json that looks like this:{“maneColor”:”silver” }I can automatically instantiate a Unicorn object wit
Craig Otis
objective-c cocoa osx nsstring nsdata
My app uses XML to save user data to a file. I have just recently received 2 reports from users who are seeing completely unexpected data in their file. Instead of XML, it looks like this:({“windows”:[{“tabs”:[{“entries”:[{“url”:”https://mail.google.com/a/cast…And a bit more from the middle of the file, which weighs in at almost 30KB:{\”n\”:\”bc\”,\”a\”:[null]},{\”n\”:\”p\”,\”a\”:[\”ghead\”,\”\”,0]},{\”n\”:\”ph\”,\”a\”:[{\”gb_1\”:\”http://www.google.com/Can anyone tell me what kind of data thi
Andrew Johnson
objective-c cocoa-touch core-data
When using CoreData, the following multi-column index predicate is very slow – it takes almost 2 seconds for 26,000 records. Please note both columns are indexed, and I am purposefully doing the query with > and <=, instead of beginswith, to make it fast:NSPredicate *predicate = [NSPredicate predicateWithFormat:@”airportNameUppercase >= %@ AND airportNameUppercase < %@ \OR cityUppercase >= %@ AND cityUppercase < %@ \upperText, upperTextIncremented,upperText, upperTextIncremented];
Alex Stone
objective-c actionscript-3 movement
What’s the best way to do movement in a 2D square grid system? I have this something that works but it seems wrong/ugly (see below).x x x x x x x x x x x x x x x x x O x x x x x x U x x x x x x x x x x x x x x x x x x x x x x x xFor example, U is the unit I want to move, and O is an impassable object like another unit or a mountain. If U can move 3 tiles, I want the moveable area (M) to look like this.x x x x x x x x x M x M x x x M M O M M x M M M U M M M x x M M M M x x x M M M x x x x x M x
Patrick
objective-c ios automatic-ref-counting core-foundation
UPDATE: This issue has been fixed as of Xcode 4.6!This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier’s excellent answer before you use it in your code.ORIGINAL POST(ARC, Xcode 4.3.1, iOS 5.1)I have a strong property of a CF type (CGImage) that I want to be automatically managed by ARC using __attribute__((NSObject)) (as in having retain & release in the synthesized setter, and it being nil’ed in dealloc), but it doesn’t work: the object
AviD
mobile risk-management ios
Being employed in the infosec field I would like to set a good example. However I also do not believe in sweating the small stuff and would like to maximize my productivity. My current workplace, while piloting byo devices, iPads etc does not yet have an enterprise iPad solution. I have a personal iPad that I would like to use to take minutes of meetings and to brainstorm via mindmaps. At previous places where this was not frowned upon, I have found it significantly better than writing on a phys
Jaydles
ios ios-6 iphone-5 maps
The initial release of Apple Maps is… challenged with regard to business listings, and lacks transit directions.But most of the other apps Tim Cook suggested in his apology fail to solve the problem: the straight-up GPS nav apps lack transit directions and have mediocre POI data, and the webapps are slow and lack many of the features of the native ones.What’s the best workaround until Google releases an iPhone native app (likely months) or Apple’s databases catch up (likely years)?
bneely
iphone ios youtube
Whenever I try and log into the native Youtube app on my iPhone, it reports ‘Authentication Failed” even though the details are 100% correct. Here’s what I’ve done so far:Youtube.com accepts my username and password on both the desktop and iPhone web app. I’ve reset my Youtube password I get the same results over 3G or wifi (tried multiple networks, incl. Apple Store), so it is not my carrier or ISP blocking Youtube. A friend logged in with his account and the iPhone accepted it, so it isn’t sp
Guy
iphone objective-c ios image-processing
I’m trying to combine two photos into one image (think a body with a hole in the face on top of a picture of a different person’s face). The top image has some semi-transparent pixels and some fully transparent pixels and I want to overlay it on top of a solid image.Here’s what I’m doing: I have a Context with the right size and I draw the bottom image on it, without any alpha (faceImage). On top of that I draw an image that has a transparent hole in it, with various levels of transparencies (co
danielpunkass
ios objective-c osx cocoa automatic-ref-counting
In Apple’s documentation about ARC, they make a point of spelling out a problematic scenario in which ARC will generate a boilerplate temporary variable behind the scenes. Search on “The compiler therefore rewrites”:https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.htmlThe gist of the warning seems to be that because the stack-based variable is “strong” and the by-reference parameter to the called method (performOperationWithError:) i
SaamJB
iphone objective-c ios
I have a UITableViewController that when a cell is pressed, I want the controller to pop itself, and then have the controller it pop’s to, push another view controller onto the stack.I am invoking this method because the popped-to viewController is the delegate of the tableViewControllerI am currently invoking this method with a delay on it, because otherwise, everything gets screwed up waiting for the animation to end. Doing it this way seems a bit hacky and seems to me like it would fail if so
Steven
objective-c ios oauth
I’ve been trying to get a basic OAuth interaction working without success. There are certainly similar questions already posed on SO, but most of them have no replies. I’m getting pretty desperate here, so I’m just going to start by posting my entire code:// OAuth parameters NSString *oauthNonce = [self genRandStringLength:20]; NSString *oauthSignatureMethod = [NSString stringWithFormat:@”HMAC-SHA1″]; time_t oauthTimeStamp = (time_t) [[NSDate date] timeIntervalSince1970];// generate OAuth signat
Robin van Dijke
ios core-data memory
I’m now stuck for about two weeks with a nasty Core Data problem. I read lots of blogpost, articles and SO questions/answers but I’m still not able to solve my problem.I ran lots of tests and was able to reduce the larger problem to a smaller one. It’s going to be a large explanation so keep with me!Problem – datamodelI have to got following datamodel:Object A has one-to-many relation with object B which has another one-to-many relation with object C. Because of Core Data recommendations I have
Nate
ios uiwebview uiscrollview uikit
The QuestionDoes anyone know of technical reasons for avoiding web views inside scroll views on iOS (assuming you’re willing to disable scrolling inside the web views themselves)?If you look at the Apple docs for UIWebView, they state:Important: You should not embed UIWebView or UITableView objects inUIScrollView objects. If you do so, unexpected behavior can resultbecause touch events for the two objects can be mixed up and wronglyhandled.My Educated GuessIt looks like maybe they’re warning you
rmaddy
ios uitabbarcontroller
This question already has an answer here:Proper way to exit iPhone application?19 answersI have a tab based app, which last tab button is “Exit” how can I quite iPhone App, on click of that last tab bar?
Robert
cocoa appkit
Is there any way to prevent the NSTokenField to select everything when pressing the ENTER key or when making to the first responder maybe using the TAB key?
Dov
objective-c cocoa unit-testing key-value-observing ocmock
I would like to test that Key-Value-Observation is working properly for a class of mine. It has one property, which depends on another. They are set up like so:+ (NSSet *)keyPathsForValuesAffectingSecondProperty {return [NSSet setWithObjects:@”firstProperty”,nil]; }- (NSArray *)secondProperty {return [self.firstProperty array]; }I want to run a unit test to verify that when firstProperty changes, an object bound to secondProperty gets a notification. At first I thought I would be able to use +[O
danielpunkass
ios objective-c osx cocoa automatic-ref-counting
In Apple’s documentation about ARC, they make a point of spelling out a problematic scenario in which ARC will generate a boilerplate temporary variable behind the scenes. Search on “The compiler therefore rewrites”:https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.htmlThe gist of the warning seems to be that because the stack-based variable is “strong” and the by-reference parameter to the called method (performOperationWithError:) i
morgancodes
objective-c cocoa cocoa-touch json
In java-land, there are a handful of useful libraries which will convert json strings to objects of matching type. The json libraries I’ve seen for cocoa simply create nested NSDictionaries and NSArrays. Is there a tool out there which will go the extra step of reconstituting whatever object type I want? So, for example, if I have a class called “Unicorn”, with a property “maneColor”, and I have json that looks like this:{“maneColor”:”silver” }I can automatically instantiate a Unicorn object wit
Craig Otis
objective-c cocoa osx nsstring nsdata
My app uses XML to save user data to a file. I have just recently received 2 reports from users who are seeing completely unexpected data in their file. Instead of XML, it looks like this:({“windows”:[{“tabs”:[{“entries”:[{“url”:”https://mail.google.com/a/cast…And a bit more from the middle of the file, which weighs in at almost 30KB:{\”n\”:\”bc\”,\”a\”:[null]},{\”n\”:\”p\”,\”a\”:[\”ghead\”,\”\”,0]},{\”n\”:\”ph\”,\”a\”:[{\”gb_1\”:\”http://www.google.com/Can anyone tell me what kind of data thi
TheAmateurProgrammer
Ben Packard
objective-c cocoa nstimer
I have a snippet of code I want to execute repeatedly, but with the ability to pause and resume it. To do this, I have utilised an NSTimer, which I can stop and start as required.Within the snippet, I use a sleep command to wait for something to update (0.3 seconds). The timer is firing every 0.5 seconds.What would be ideal is to keep the stop and start functionality, and be firing every 0.3 seconds, but to not have to explicitly say I want it to fire every x seconds. The 0.5 is completely ar
Dr.Kameleon
objective-c osx cocoa sandbox nssavepanel
I know about Sandbox limitations and and my usual technique of having the user save a file is via the NSSavePanel, which automagically grants the app the necessary priviliges to the location, as indicated by the user.Now, here’s the… not-so-uncommon scenario :User creates a new file, in my app Saves is for the first time (so, there’s a good reason for the NSSavePanel to show up) Then edits the contents of the document (please, note that my app is not a typical NSDocument-compliant one) And fin
Robert Kang
objective-c cocoa apache cxf asihttprequest
I am working on a project involving Apache CXF at server side providing RESTful webservice, taking in and out in JSON format. At the client side is an Mac OSX app with ASIHTTPRequest and SBJson. I had various issues in the last few days, and was not able to find out a solution.At server side:@Override @POST @Path(“/testService/”) @Consumes(MediaType.APPLICATION_JSON) public Boolean service1(SomeMetaData metaData) {return this.testMetaData(metaData); }At client side:NSString *requestURLString = [
Nick Hutchinson
c cocoa file-io grand-central-dispatch
Inspired by Apple’s documentation, I’m experimenting with using a GCD dispatch source to read asynchronously from a file, instead of using the traditional NSInputStream and run loop based approach.However, I’m not sure how to detect when I’m done reading the file. With NSInputStream, your delegate get sent a NSStreamEventEndEncountered event. For dispatch sources, I assumed the event handler would get called at the end-of-file, but this doesn’t seem to be the case. What am I missing?Here’s my co
patrix
osx torrent
I have tried (and failed) to install the Ocelot torrent tracker (backend) together with the Gazelle (frontend). For now I used the ocelot-tracker source code from this GitHub repository, but unfortunately I haven’t found a way to compile this code.The installation fails with an error. There is a makefile but when I run make I getg++ -c -O2 -fomit-frame-pointer -march=native -fvisibility-inlines-hidden -fvisibility=hidden -Wall -std=c++0x -iquote -Wl,O1 -Wl,–as-needed -I/usr/include/mysql -I/usr
Mikey T.K.
osx lion networking dns
I’ve recently (as in minutes ago) added a hostname and reverse (A and PTR) records for a hostname on my internal network, using a Bind DNS server. For some reason, i can both dig and nslookup this new name successfully, but ping and my GUI applications can not resolve the name.I have attempted flushing the DNS cache on my local machine with dscacheutil -flushcache to no effect.Here’s an example of my session (names, IPs changed for security):$ nslookup newbox.internal server 10.0.0.2 address
Zack
ruby-on-rails osx
I am attempting to run “bundle install” but keep getting the following error messages… ~/src/*******/******_bundle/trunk zackwarburg $ bundle install Fetching source index from https://gemini.atl.********.net/ Fetching gem metadata from https://rubygems.org/……… Fetching gem metadata from https://rubygems.org/……. Using rake (0.9.2.2) Using i18n (0.6.1) Using multi_json (1.5.0) Using activesupport (3.2.10) Using builder (3.0.4) Using activemodel (3.2.10) Using erubis (2.7.0)
Chase Ries
osx git unix github
I have a problem that sprang up out of nowhere in the past two or three days. Whenever I’m using Git in Terminal (which is pretty much always), if I visit GitHub in my browser or even visit a page that links to GitHub, an OSX dialogue pops up that readsGithub Conduit wants to use your confidential information stored in “privateKey” in yourkeychain.Do you want to allow access to this item?[ ? ][ Always allow ][ Deny ][ Allow ]To begin with, I don’t know what it’s accessing — my SSH key, I assume
Carl Norum
bash scripting osx
I am attempting to automate moving files from a folder to a new folder automatically every night using a bash script run from applescript on a schedule. I am attempting to write a bash script on Mac OSX, and it keeps failing. In short this is what I have (all my ECHOs are for error checking):#!/bin/bashfolder = “ABC”useracct = ‘test’day = date “+%d”month = date “+%B” year = date “+%Y”folderToBeMoved = “/users/$useracct/Documents/Archive/Primetime.eyetv”newfoldername = “/Volumes/Media/Network/$fo
danielpunkass
ios objective-c osx cocoa automatic-ref-counting
In Apple’s documentation about ARC, they make a point of spelling out a problematic scenario in which ARC will generate a boilerplate temporary variable behind the scenes. Search on “The compiler therefore rewrites”:https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.htmlThe gist of the warning seems to be that because the stack-based variable is “strong” and the by-reference parameter to the called method (performOperationWithError:) i
Craig Otis
objective-c cocoa osx nsstring nsdata
My app uses XML to save user data to a file. I have just recently received 2 reports from users who are seeing completely unexpected data in their file. Instead of XML, it looks like this:({“windows”:[{“tabs”:[{“entries”:[{“url”:”https://mail.google.com/a/cast…And a bit more from the middle of the file, which weighs in at almost 30KB:{\”n\”:\”bc\”,\”a\”:[null]},{\”n\”:\”p\”,\”a\”:[\”ghead\”,\”\”,0]},{\”n\”:\”ph\”,\”a\”:[{\”gb_1\”:\”http://www.google.com/Can anyone tell me what kind of data thi
the Tin Man
ruby-on-rails ruby osx terminal
I previously used a package installer from railsinstaller.org to set up an installation of Rails on my Mac OS X system. There’s always been the odd problem, but nothing major. I decided to delete it completely and start again, but now I’m seeing more problems.Is it worth completely deleting my installations of Git, Homebrew, Ruby and anything else that you might recommend, and just starting again perhaps?Here’s the problem I’m getting when typing into terminal:$ rvm reinstall 1.9.3device-3ebf56
nrser
osx git plist defaults
how can i parse the output of the OS X defaults read terminal command?it appears to output the ‘old’ NeXTSTEP plist format; things that look like:{ “Apple Global Domain” = {AppleAntiAliasingThreshold = 4;AppleCollationOrder = root;i tried writing the output to a file and converting with plutil, but it chokes:> defaults read > defaults.txt > plutil -convert xml1 defaults.txt 2014-02-02 21:29:14.856 plutil[56896:707] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing s
user2776228
osx brew
I have some troubles with brew doctor:Error: /usr/local/Library/Formula/enchant.rb:44: syntax error, unexpected $end, expecting kEND Please report this bug:https://github.com/mxcl/homebrew/wiki/troubleshooting /usr/local/Library/Homebrew/formulary.rb:40:in `require’ /usr/local/Library/Homebrew/formulary.rb:40:in `klass’ /usr/local/Library/Homebrew/formulary.rb:90:in `get_formula’ /usr/local/Library/Homebrew/formulary.rb:175:in `factory’ /usr/local/Library/Homebrew/formula.rb:432:in `factory’ /us
Web site is in building