使用NSInteger的好处一

[iOS]NSInteger int long区别 为什么要写这篇文章呢?源于初学iOS开发中遇到的一个蛋疼的bug,在网络请求json后转model时,对其中照片宽高进行赋值时错误的使用了NSUInteger进行强转,导致复制后的图片size为负数,表现在UI上就是所有图片都为默认大小而不是真实大小…不过这也提醒大家编程时要考虑到极端情况起码有个默认值兜底???? NSInteger、int、long NSInteger定义的头文件: #if __LP64__ || 0 || NS_BUILD_32_LIKE_64 typedef long NSInteg 阅读详情

今天在困惑int和long的使用。

查到c语言中,int和long的字节数是和操作系统指针所占位数相等。

但c语言中说,long的长度永远大于或等于int

objective-c里,苹果的官方文档中总是推荐用NSInteger

它和int有什么区别呢,stackoverflow这帮大神给了答案。

原来在苹果的api实现中,NSInteger是一个封装,它会识别当前操作系统的位数,自动返回最大的类型。

定义的代码类似于下:

#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64

typedef long NSInteger;

typedef unsigned long NSUInteger;

#else

typedef int NSInteger;

typedef unsigned int NSUInteger;

#endif


You usually want to use NSInteger when you don't know what kind of processor architecture your code might run on, so you may for some reason want the largest possible int type, which on 32 bit systems is just an int, while on a 64-bit system it's a long.


当你不知道你的操作系统是什么类型的时候,你通常会想要使用NSInteger,所以或许你想要你的int类型范围尽可能的大,用NSInteger,32位系统NSInteger是一个int,即32位,但当时64位系统时,NSInteger便是64位的。


vivado中出现ERROR: [Labtools 27-2220]检测不出开发板 这个错误可能是由于 Vivado 工具中的 cs_server.exe 文件没有正确安装或者文件路径不正确导致的。你可以尝试以下步骤来。时间: 2023-08-16 12:05:50 浏览: 767。希望以上方法能够帮助你。 阅读详情

相关推荐

告别Docker Desktop!Colima在Mac上的5分钟极速安装与配置指南(M1芯片实测)

本文详细介绍了如何在Mac(尤其是M1芯片)上快速安装和配置Colima,作为Docker Desktop的免费替代品。通过优化配置和实战指南,帮助开发者提升容器运行效率,减少资源占用,实现丝滑的开发体验。

weixin_28839601的博客 446

NSInteger,NSUInteger,CGFloat

前导 int:4个字节,一个字节8位,占32位的整数 long:8个字节,占64位的整数 (3)在int与long前加上unsigned 表示无符号 (4)float:占32位的浮点数 (5)double:占64位的浮点数 NSInteger、NSUInteger、CGFloat不是类,而是基本数据类型 NSInteger在32系统中就是int,在64位系统中就是long, 现在咱们的苹果真机都是64位系统 NSUInteger在32系统中就是unsigned int,在64位系统中就是unsigned

More reading and learning to become excellent 1357

编译原理实验二:LL(1)分析法(附C/C++完整代码)

本文讲述了LL(1)文法的原理及如何用C语言实现。并在给出的代码中实现了消除文法的左递归,First集,Follow集,select集的输出,构造预测分析表并输出,和对任意输入字符串的分析。程序总流程为:从文件读取文法 -> 输出文法信息 -> 消除左递归并输出消除后的文法 -> 计算First集并输出 -> 计算Follow集并输出 ->计算select集并输出 -> 判断是否是LL(1)文法 -> 构造预测分析表并输出 ->手动输入要分析的字符串 -> 输出分析过程和结果读取文件。

W_Wmwmwm的博客 6192

OC基础学习 int、NSInteger、NSUInteger的区别

int、NSInteger的区别 NSInteger会自动识别当前电脑系统是32位还是64位数,然后自动返回最大的类型(int还是NSInteger)。例如,当前电脑为32位系统,你声明的NSInteger自动变为int。当前电脑为64位系统,你声明的NSInteger还是NSInteger。 所以32位系统,int的长度等于NSInteger的长度;64位系统,int的长度小于NSInteger的长度;也就是说NSInteger的长度一定是大于等于int的长度的。 知道了这个原理,当你不知道电脑的系统是几

凯撒大帝的博客 2186

MobaXterm隧道配置详解:为PyCharm远程开发打通‘最后一公里’

本文详细解析了如何利用MobaXterm配置SSH隧道,实现PyCharm远程开发的高效连接。通过本地端口转发技术,开发者可以安全访问内网服务器,特别适用于需要通过跳板机的复杂网络环境。文章涵盖从基础配置到企业级运维的全套解决方案,包括性能优化、安全加固等实用技巧。

weixin_30566063的博客 504

matlab电偶极子源码,电偶极子的MATLAB场模拟

电偶极子周围电场电势分布的MATLAB三维模拟Matlab可以用于模拟四维场的效果,本文以电偶极子的电场和电势场为例展示MATLAB在该方面领域的应用。摘要电偶极子由一个正电荷和一个负电荷组成,其电场和空间电势分布与单电荷相比具有一些重要的特性。本文将给出电场和电势场的近似表达式。这两个量的精确表达式是复杂的,不太常用,因此 MATLAB 被采用来操作精确值和绘制三维分布的远区域, 近区域和一侧区...

weixin_35135480的博客 3150

int、 NSInteger、 NSUInteger、NSNumber之间的区别

int : 当使用int类型定义变量的时候,可以像写C程序一样,用int也可以用NSInteger,推荐使用NSInteger ,因为这样就不用考虑设备是32位还是64位了。NSUInteger:是无符号的,即没有负数NSInteger:是基础类型,是有符号的。NSNumber:是一个类,比如在字典,数组中就只能存NSNumber,而不能存放int或者NSInteger这些基本类型。这里补充一下NS

凉城旧梦的博客 908

手把手教你RK3568 MIPI屏驱动适配,纯干货!

RK3568 作为一款高性能的多媒体处理器,在嵌入式领域中备受瞩目。它采用了先进的 22nm 制程工艺,搭载四核 Cortex-A55 处理器,这种架构为芯片提供了高效的功耗比,使其在运行各种复杂任务时,既能保证性能,又能有效控制功耗。在实际应用中,无论是多任务处理还是运行大型应用程序,RK3568 都能凭借其四核 Cortex-A55 处理器,实现流畅的操作体验,满足智能设备对高性能和低功耗的需求。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 4071

数字类型(NSInteger,NSUInteger,NSNumber)

在Objective-C中,我们可以使用c中的数字数据类型,int、float、long等。它们都是基本数据类型,而不是对象。也就是说,不能够向它们发送消息。然后,有些时候需要将这些值作为对象使用。 NSInteger、NSUInteger 当你不知道程序运行哪种处理器架构时,你最好使用NSInteger,因为在有可能int在32位系统中只是int类型,而在64位系统,int可能变是...

270

2025爬虫实战:某音直播间实时弹幕获取原理及源码分析

某音直播弹幕虽然没有直接挂在 DOM 上,但由于用的是西瓜播放器,弹幕是通过 JS 接口动态渲染的,这就给了我们 Hook 的机会。关键点是找到调用的位置,然后拦截并输出对象里的message字段。这个思路其实也适用于其他前端渲染的播放器,比如 B 站的 DPlayer、HLS.js、甚至很多自研播放器都有类似结构。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1814

YOLOv8n轻量化实战:10分钟打通实时摄像头目标检测,附参数调优与避坑指南

本文介绍了如何快速入门YOLOv8目标检测框架,通过摄像头实战实现实时检测。YOLOv8凭借轻量化架构和跨平台优势,是新手入门的理想选择。文章详细讲解了环境搭建(1分钟完成)、核心代码逻辑(3分钟掌握)以及性能调优技巧(3分钟进阶),提供可直接运行的代码示例。重点包括:模型选择(优先yolov8n.pt)、摄像头参数优化、置信度阈值调整、检测类别指定等实用技巧,帮助开发者快速实现10-15FPS的实时检测效果,并针对不同场景提供优化建议。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 370

NSInteger、NSUInteger、CGFloat

NSInteger、NSUInteger、CGFloat不是类,而是基本数据类型

王光荣的专栏 6505

微信小程序 - 强力解决wx.getLocation定位不准的问题,如何修正微信小程序wx.getLocation获取用户位置信息不准确解决办法(高精度定位还是不够精准,定位不准有偏差,彻底消除误差)

如何解决getLocation定位偏差的问题?微信小程序API—wx.getLocation定位不准的问题,微信小程序wx.getLocation获取用户位置信息不准确解决办法,解决微信小程序wx.getLocation定位不准的问题,定位不准确,实际位置偏差大,相差几公里,微信小程序wx.getLocation获取用户位置信息不准确解决办法,关于微信小程序获取准确定位的方法及解决定位不准确的问题,偏差太多好几百米,wx.getLocation 返回定位精度不准问题,如何消除这个误差,开启高精度定位依旧有误

🏆 前端领域优质创作者 1万+

oc/object-c/ios用int还是NSInteger

当需要使用int类型的变量的时候,可以像写C的程序一样,用int,也可以用NSInteger,但更推荐使用NSInteger,因为这样就不用考虑设备是32位的还是64位的。 可以看如下定义:#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_...

weixin_34241036的博客 116

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

iOS开发之int,NSInteger,NSUInteger,NSNumber的使用

转自:http://chensmiles.blog.163.com/blog/static/121463991201296101228806/ If you’ve ever found yourself scratching your head thinking “now which one should I be using, NSNumber or NSInteger?” the

wangwei0327的专栏 1398

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[IOS]int,NSInteger,NSUInteger,NSNumber使用

1.当需要使用int类型的变量的时候,可以像写C的程序一样,用int,也可以用NSInteger,但更推荐使用NSInteger,因为这样就不用考虑设备是32位的还是64位的。 2.NSUInteger是无符号的,即没有负数,NSInteger是有符号的。 3.有人说既然都有了NSInteger等这些基础类型了为什么还要有NSNumber?它们的功能当然是不同的。  NSInteger是基础

万里独行 2260

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

NSInteger和Int的转换

NSString *a = @"234"; int abc = [a intValue]; ….. doubleValue; floatValue; boolValue; integerValue; ----------------------------------------------------- NSInteger转换为int: NSInteger myIntege...

编程资料大全 7243

nsinteger转float_int、NSInteger、NSNumber和NSString以及相互转换

NSInteger:#if __LP64__ || TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64typedeflongNSInteger;typedef unsignedlongNSUInteger;#elsetypedefintNSInteger;typedef unsignedi...

weixin_35725559的博客 1112

int和NSInteger区别

今天在困惑int和long的使用。 查到c语言中,int和long的字节数是和操作系统指针所占位数相等。 但c语言中说,long的长度永远大于或等于int objective-c里,苹果的官方文档中总是推荐用NSInteger 它和int有什么区别呢,stackoverflow这帮大神给了答案。 原来在苹果的api实现中,NSInteger是一个封装,它会识别当前操作

legend的专栏 823

【iOS知识学习】_int、NSInteger、NSUInteger、NSNumber的区别和联系

1、首先先了解下NSNumber类型: 苹果官方文档地址:https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSNumber_Class/Reference/Reference.html NSNumber是NSValue的一个子类,它是一个对象来存储数字值包括bool

weasleyqi的专栏 6万+

swift 中的 NSInteger 类型

NSInteger type in swift 在Swift中, NSInteger是Int的别名, 所以它们是同一个基本数据类型, 是完全等同的. /* NSObjCRuntime.h Copyright (c) 1994-2012, Apple Inc. All rights reserved. */ public typealias NSInteger = Int public var NSIntegerMax: Int { get } ...

侯仕奇的博客 810

使用NSInteger容易忽视的错误

682

NSInteger 和int区别

今天在困惑int和long的使用。 查到c语言中,int和long的字节数是和操作系统指针所占位数相等。 但c语言中说,long的长度永远大于或等于int objective-c里,苹果的官方文档中总是推荐用NSInteger 它和int有什么区别呢,stackoverflow这帮大神给了答案。 原来在苹果的api实现中,NSInteger是一个封装,它会识别当前操作系统的位数,自动返回

springlzi的专栏 794

NSInteger VS int

常能看到有人说苹果g

dfqin的专栏 2511

NSInteger 与 NSUInteger 和 int与 NSInteger 区别

先说说NSInteger 与 NSUInteger,在看书上代码是遇见NSInteger和NSUInteger,不知道什么时候用NSInteger,什么时候用NSUInteger,在网上搜了一下,NSUInteger是无符号的整型, NSInteger是有符号的整型,在表视图应用中常见 NSUInteger row= [indexPath row];因为这是显示tableViewCell有多少个,

新风作浪的博客专栏 2万+

NSInteger取值范围

在64位机上代码测试了一下结果是: 2015-04-21 19:46:54.046 here[2945:209062] 2的62次方是4611686018427387904 2015-04-21 19:46:54.046 here[2945:209062] 2的63次方减1是9223372036854775807 2015-04-21 19:46:54.047 here[2945:2

FengziTianYu的专栏 1万+
上一篇: 关于NSUInteger的奇怪问题
下一篇: Charles使用
安子就是安子
博客等级 码龄17年 35粉丝 68原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值