Common objective-C codes

Source: Internet
Author: User

Conversion between nsimage and nsdata

Nsdata * imagedata = [nsdata
Datawithcontentsoffile: ImagePath];


Uiimage * aimage = [uiimage
Imagewithdata: imagedata];


// Uiimage-> nsdata


Nsdata * imagedata = uiimagepngrepresentation (aimae );

Random Number

Srandom (Time (null ));

Generate 5 ------ 20
Between a random number

Int n =
5 + (INT) (20.0 * (random ()/(rand_max +
1.0 )));

SrandAndRandIt is not officially recommended. The reason is that the random number generation performance is not very good, 

The random number is random.RandomGood,
In addition, it is not thread security.

Nslog (@ "% @", nsstringfromselector (_ cmd ));

Go to the program directory under simulator debugging

/Private/var/root/library/Application Support/iPhone simulator/5.1/Applications

Read serialized files

Nsstring * resourcepath = [nsbundle
Mainbundle] resourcepath];

Nsstring * Path = [nsstring
Alloc] initwithformat: @ "% @/president. plist", resourcepath];

Nsdata * Data = [nsdata
Alloc] initwithcontentsoffile: path];

President * thepres = [nskeyedunarchiver
Unarchiveobjectwithdata: Data];

Save serialized files

Nsstring * resourcepath = [nsbundle
Mainbundle] resourcepath];


Nsstring * Path = [nsstring
Alloc] initwithformat: @ "% @/president. plist", resourcepath];


Nsdata * Data = [nskeyedarchiver
Archiveddatawithrootobject: Self. President];


If ([Data
Writetofile: path atomically: No])

{


Uialertview * Alert = [uialertview
Alloc] initwithtitle: @ "system"
Message: @ "saved successfully! "Delegate: Nil
Cancelbuttontitle: @ "OK"
Otherbuttontitles: nil,
Nil];

[Alert
Show];

[Alert
Release];

}

Access master delegate

Appdelegate * delegate = [[uiapplication
Sharedapplication] Delegate];

Access the main program


Uiapplication * APP = [uiapplication
Sharedapplication];

2) Add a custom post-generated script

Add a phase in build phases, add in the lower right corner
Build phase, click Add run script, and enter the following script

Export codesign_allocate =/developer/platforms/iphoneos. Platform/developer/usr/bin/codesign_allocate

If ["$ {platform_name}" = "iphoneos"]; then

/Developer/iphoneentitlements401/gen_entitlements.py "My. Company. $ {project_name}" $ {built_products_dir}/$ {wrapper_name}/$ {project_name}. xcent ";

Codesign-F-s "iPhone developer" -- entitlements "$ {built_products_dir}/$ {wrapper_name}/$ {project_name }. xcent "" $ {built_products_dir}/$ {wrapper_name }/"

Fi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.