I still believe in no-warnings coding policy. Old problem, new solution.
Code warnings are often signs of real problems and have to be checked each and all. Many times you can rewrite the code in a better way, but sometimes that's not possible. For example generic protocol API offers method parameters, which are not needed in certain cases. You get the "Unused Parameter" warning.
What to do?
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
Monday, May 14, 2012
Friday, September 3, 2010
How to Create Human-readable Geo Coordinate Strings
How to create human-readable coordinate strings, a code snippet that I wrote long time ago. Released here as a reminder for The Next Time (there's always a next time):
CLLocationCoordinate2D loc = mapView.userLocation.coordinate;Based on Wikipedia article about Geographic coordinate conversion.
BOOL loc_NS;
if (loc.latitude > 0)
{
loc_NS = YES;
}
else
{
loc_NS = NO;
loc.latitude *= -1;
}
int lat_d = floor(loc.latitude);
loc.latitude -= lat_d;
loc.latitude *= 60;
int lat_m = floor(loc.latitude);
loc.latitude -= lat_m;
loc.latitude *= 60;
int lat_s = floor(loc.latitude);
BOOL loc_WE;
if (loc.longitude > 0)
{
loc_WE = NO;
}
else
{
loc_WE = YES;
loc.longitude *= -1;
}
int lon_d = floor(loc.longitude);
loc.longitude -= lon_d;
loc.longitude *= 60;
int lon_m = floor(loc.longitude);
loc.longitude -= lon_m;
loc.longitude *= 60;
int lon_s = floor(loc.longitude);
location.text = [NSString stringWithFormat:@"Location: %d°%d′%d″%@ %d°%d′%d″%@",
lat_d, lat_m, lat_s, loc_NS ? @"N" : @"S",
lon_d, lon_m, lon_s, loc_WE ? @"W" : @"E"];
Labels:
CLLocationCoordinate2D,
code,
coordinates,
iphone,
latitude,
location,
longitude,
StringWithFormat
Tuesday, June 22, 2010
Dereference of null pointer
XCode Build and Analyze command finds several "Deference of null pointer" warnings in some 3rd party sources.
Pointer with a possible value NULL is used like it always points to a valid memory area:
How to fix: check pointer value before trying to use it. Code safe.
Pointer with a possible value NULL is used like it always points to a valid memory area:
#include <stddef.h>
int *p = NULL;
*p;Trying to use a null pointer *p will cause undefined behaviour, depending on compiler and operating system. Reading from it might return garbage values, writing to it might corrupt memory somewhere else. Null pointer errors have also been used to go around security systems. Protected mode OSes usually stop the application trying to do such things, causing application to crash instead of the OS.How to fix: check pointer value before trying to use it. Code safe.
Monday, June 14, 2010
Learn iPhone Programming by Example
Best way to learn is by example, at least for some people. Haven't checked these myself, but like the idea: 35 open source application.
ManiacDev.Com: 35 Open Source iPhone App Store Apps – Updated With 10 New Apps!
Looking at titles and descriptions, there are several I wish to check later. Might even use a few!
ManiacDev.Com: 35 Open Source iPhone App Store Apps – Updated With 10 New Apps!
Looking at titles and descriptions, there are several I wish to check later. Might even use a few!
Monday, June 7, 2010
How to Make Instruments Show Your Own Code
Debugging memory leaks with Instruments. Great tool, but would be more useful, if I could see there references to my code.
Turned out it's a known iPhone OS 3.0 defect, almost two years old! No idea why it hasn't been fixed by Apple. Maybe old SDKs are not supported on purpose, which does make some business sense.
How to fix: Go to your Xcode project, select project info, go to Build tab and search Base SDK. Change your project Base SDK to 3.1. I had there 3.0, which seems to be a known defect.
Turned out it's a known iPhone OS 3.0 defect, almost two years old! No idea why it hasn't been fixed by Apple. Maybe old SDKs are not supported on purpose, which does make some business sense.
How to fix: Go to your Xcode project, select project info, go to Build tab and search Base SDK. Change your project Base SDK to 3.1. I had there 3.0, which seems to be a known defect.
- Build - Clean All Targets - select all - Clean
- Build - Build and Analyze
- Run - Run with Performance Tool - Leaks
- Stop
- Open popup item with application name - Launch Executable - Choose Executable
- Browse to your Build directory and select your application
- Record (the red Dot button)
Labels:
code,
debug,
Instruments,
iphone,
memory leak,
simulator,
source,
Xcode
Tuesday, May 4, 2010
Change of Blog Scope
Since iPhone is not everything I do, I have decided to start writing short reminders about other areas, too.
Just FYI, nothing to worry about.
Just FYI, nothing to worry about.
Tuesday, January 26, 2010
How to Show Source Code in Blogger
Amazing, but Blogger still doesn't seem to support presenting source code as-is. There are several tips how to do it yourself, for example "Adding Syntax Highlighting to Blogger" by Heisencoder. Unfortunately none of these ways are very simple.
For now I'll settle for non syntax colored plain code lines. I'll use "HTML-encode a String Online" tool to start with.
Good enough, right ROI.
For now I'll settle for non syntax colored plain code lines. I'll use "HTML-encode a String Online" tool to start with.
Good enough, right ROI.
Subscribe to:
Posts (Atom)
