Is there any way to store unsigned long in core data?

CoreData provides Integer 16, Integer 32 and Integer 64 storage, but doesn't support any sign qualifiers. You can store an unsigned int (32 bit) as a signed long (64 bit) and make sure the value is preserved for the full range, but an unsigned long seems to require a 128 bit signed integer to store, which of course isn't supported by CoreData. Is there any way then to store unsigned long in coreData?

-------------Problems Reply------------

[Previous comment promoted to answer]

Sounds like it is the bit pattern which is important to you and not the integer value per se. You can store it as a signed - just cast it as C signed<->unsigned casts don't enforce mathematical correctness and just preserve the bits. Cast it back to use it.

Follow up question:

In general yes in (Obj-)C(++) you can store an unsigned integer value into a variable with the equivalent signed integer type, and vice-versa. C casts from signed -> unsigned by definition equate to a bit-copy when using 2's complement integers and the two types are the same size. Going the other way, unsigned -> signed, is "implementation defined" - which in practice usually means a bit-copy. Clang & GCC use a bit-copy for both, but if you want to be absolutely certain you can use a union:

unsigned long r;
long l;

r = (unsigned long)l; // will always work (cast optional)

// following is l = (long)r (cast optional) without "implementation defined" risk
{ union { long sValue; unsigned long uValue; } tmp; tmp.uValue = r; l = tmp.sValue;}

But seriously I doubt anybody would! (Note: Clang at least will compile it down to a straight assignment (bit-copy).)

If you really need the full precision of 64 bit unsigned, you can make it transformable (check the documentation about storing Non-Standard Persistent Attributes). CoreData let's you store just about anything that way. But you probably don't need the full 64-bit precision...?!?

You could always convert [de]serialize it as a string. It isn't particularly clean, but it gives you the ability to store it as long as you can parse it back into an unsigned long.

An unsigned long is not 128bits (yet).
(or do you have a 128bits CPU?)

On a Mac, depending on your CPU architecture, it may be 32 or 64 bits.

See with:

NSLog( @"%u", sizeof( unsigned long ) );

So basically an unsigned long will be compatible will Integer32 or Integer64.

Category:cocoa Views:1 Time:2012-01-19

Related post

  • How should I store UIImages within my Core Data database? 2010-10-11

    I am developing an application which demands around 100 images or maybe more to be pre-inserted into the Core Data database along with other related information. Now I can easily add other data by just writing a few lines of code but for UIImages I a

  • Store negative integer in Core Data 2010-12-21

    I can properly assign and retrieve a positive integer to an attribute of a managed object model instance. However, assigning a negative integer to this attribute records the number "4294967295" to my core data persistant store (an xml file). Thus, wh

  • How to store Twitter ID in Core Data objects 2011-12-07

    Any idea what is the best way to store Twitter's tweet ID (and other Twitter data item IDs in general) in a Core Data field? This is to locally cache tweets (and other Twitter data) and will be used as the primary unique ID to link the local data wit

  • Is a Persistent Store a requirement for Core Data on the iPhone? 2009-07-23

    I'm looking to use Core Data within my iPhone app. The app doesn't really need to store the data that is used, but it needs to be managed and queryable. Can Core Data be used for datasets that exist purely in memory and are not persisted to the disk?

  • Store specific interactions with Core Data 2009-08-04

    I was reading the docs on core data looking to speed up my search. I found the following and was slightly confused as to what it meant: The SQL store, on the other hand, compiles the predicate and sort descriptors to SQL and evaluates the result in t

  • How to store an image in Core Data? 2010-06-06

    Just a guess: I make an attribute and make it's type "binary". But in the end, how would I use that? I guess there is an NSData behind the scenes? So that attribute actually takes an NSData? --------------Solutions------------- This question has been

  • App Store release using wrong Core Data Version 2012-02-29

    My released version appears to be using a old model version of Core Data, xxxDB 101j instead of xxxDB as defined in the VersionInfo.plist (package contents of xxx.xcarchive submitted to the app store). This has not been an issue on development device

  • What data type should I use to store a GUID in Core Data? 2012-04-27

    I'm going to be generating CFUUID objects (if there's a better way to create a GUID on iOS, let me know) that need to be persisted using Core Data. There is no GUID data type in Core Data. What's the preferred type? It looks like CFUUID objects easil

  • Core Data with in-memory store 2009-11-07

    I want to use Core Data as a cache for a larger dataset on a database server. Not all data will be in memory. When thinking about this further 2 questions came to mind: Can faulting (for example for 1-n relationships) be used with the in-memory persi

  • How to store Matrix or Vector data structure in Core Data? 2010-06-04

    I am building an iPhone application that needs to store some sort of matrix or vector data in core data. For some unknown reason, the iPhone SDK does not include any kind of matrix data structure in its foundation classes, so I built my own data stru

  • iOS Development: Can I store an array of integers in a Core Data object without creating a new table to represent the array? 2010-12-27

    I'm using Core Data and I'm trying to figure out the simplest way to store an array of integers in one of my Core Data entities. Currently, my entities contain various arrays of objects that are more complex than a single number, so it makes sense to

  • Store NSArray In Core Data Sample Code? 2010-12-28

    Ey guys, I have been searching for some sample code on how to store an NSArray in Core Data for awhile now, but haven't had any luck. Would anyone mind pointing me to some tutorial or example, or better yet write a simple sample as an answer to this

  • Store image in core data and Retina Display? 2011-01-16

    I have an app that has hundreds of words with 3/4 images for each word. I have 2 versions of each word one for iOS 3 and one for retina display. I wish to save the images as data and connect them to the appropriate word so it will be easy to pull the

  • Memory buildup when parsing XML into a Core Data store using NSXMLParser 2011-02-19

    I have a problem with an app that takes an XML feed, parses it, and stores the results into Core Data. The problem only occurs on the very first run of the app when there is nothing in the store and the whole feed is parsed and stored. The problem is

  • Core Data: Persistent Store Works in Xcode but not on Device 2011-02-25

    I am using Core Data in my iPhone apps. It works fine when I use it in the simulator but when I deploy it to device, the value of my Core Data store is not found to my application. If I insert a value on the iPhone it finds the value in Core Data. I

  • How to Test Core Data Migration With an App Already in the App Store? 2011-06-01

    We have an app that is currently in the app store. It uses Core Data as its persistence mechanism. We have a new version ready to go, and it has some schema changes. Specifically, we have added 1 new entity and added a new attribute to an existing en

  • Store 600 sound files, 5-20kb each, inside core data 2011-11-10

    I know "I should not store large files in core data and it is better to save them in the file system". But... I still wish to try this out as my sound files are between 5-20 kb each and to my needs it will be great if they will be in core data. to be

  • How do I map and store images using Core Data and RestKit? 2011-12-16

    Using images with Core Data isn't a problem. There are a lot of examples out there on how to do that like: How should I store UIImages within my Core Data database? I want to know how to use RestKit to download images and map them correctly to Core D

  • How can I retrieve a textfields text and store it as an integer 32 in core data? 2012-05-03

    I'm trying to get the textfields text, convert it to an int, and store it in a core data integer 32 attribute. I'm getting an error in the process: Implicit conversion of 'int' to 'NSNumber' disallowed with arc Here is What I've tried: // trying to c

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.133 (s). 11 q(s)