使用 Next.js、next-on-netlify 构建,相关页面使用 getServerSideProps。
\n平均超过 10 次页面加载:
\n我\xe2\x80\x99ve 分析了从 getServerSideProps 调用到页面函数返回的时间,并且在所有环境中,该时间可靠地花费 < 1 秒。
\n我\xe2\x80\x99ve也尝试删除页面中的所有内容和道具中的请求,并且对Netlify功能没有任何影响。
\n如何分析瓶颈所在?这可能是 Netlify 的问题吗?
\n所以,我正在尝试定义一个宏来简化以下代码:
for (vector<TYPE>::iterator iter = iterable.begin();
iter != iterable.end(); iter++)
Run Code Online (Sandbox Code Playgroud)
和
for (map<TYPE, TYPE>::iterator iter = iterable.begin();
iter != iterable.end(); iter++)
Run Code Online (Sandbox Code Playgroud)
等等
到目前为止,我已经有了
#define every(iter, iterable) ::iterator iter = iterable.begin(); iter != iterable.end(); iter++
for (vector<TYPE> every(iter, iterable))
Run Code Online (Sandbox Code Playgroud)
但我想进一步简化这一点.
理想情况下,我希望能够做到
for (every(iter, iterable))
Run Code Online (Sandbox Code Playgroud)
这意味着我需要以某种方式获得class<TYPE>可迭代对象.这可能吗?如果是这样,我该怎么办?
iterator对象的(相对)大型代码库.#define every(iter, iterable) typeof(iterable.begin()) iter = iterable.begin(); iter != iterable.end(); iter++
for (every(iter, iterable))
Run Code Online (Sandbox Code Playgroud) 我有一个MKMapView应该使用自定义视图(而不是蓝点)跟踪用户的位置.为了将此视图替换为蓝点,我将其返回:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == [mapView userLocation])
{
return userLocationView;
}
}
Run Code Online (Sandbox Code Playgroud)
为了初始化跟踪,我打电话
[mapView setShowsUserLocation: YES];
[mapView setUserTrackingMode: MKUserTrackingModeFollow animated: NO];
[mapView setDelegate: self];
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,-mapView:didUpdateUserLocation:当应用程序加载时会调用一次.不幸的是,除非我-mapView:viewForAnnotation:改为具有以下实现,否则它永远不会被再次调用:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if (annotation == [mapView userLocation])
{
return nil;
}
}
Run Code Online (Sandbox Code Playgroud)
通过这些更改,地图会加载蓝点作为用户位置的指示符,并且-mapView:didUpdateUserLocation:会像预期的那样频繁调用.
是否有某种互斥性来跟踪用户的位置并拥有自定义用户位置视图?我怎么能让两者都发生?
该项目证明了这个问题.https://dl.dropbox.com/u/2338382/MapKitFuckery.zip
这很可能是一个错误,我已将其作为雷达提交.在此期间,接受的答案应该证明是充分的.然而,值得注意的是,我必须完全放弃,[mapView userLocation]并且[mapView showsUserLocation]仅仅支持自定义注释和CLLocationManager.
在Cocoa中,Apple经常使用以下范例:
[NSApplication sharedApplication]
[NSNotificationCenter defaultNotificationCenter]
[NSGraphicsContext currentContext]
[NSCalendar currentCalendar]
Run Code Online (Sandbox Code Playgroud)
等等.
他们也会偶尔使用的范例,我觉得是远有大量的代码时更清晰.
NSApp //which maps to [NSApplication sharedApplication]
Run Code Online (Sandbox Code Playgroud)
我希望能够在我自己的类中以及对其他类的扩展中使用这种全局变量.
MYClassInstance
NSDefaultNotificationCenter
NSCal /* or */ NSCurrentCalendar
Run Code Online (Sandbox Code Playgroud)
等等.
#define.简单地说#define NSCal [NSCalendar currentCalendar],但是就像我们现在所知道的那样,宏是邪恶的(或者他们说的),它似乎不是正确的Cocoa方式.
我能找到的唯一来源NSApp是APPKIT_EXTERN id NSApp;,这不是完全可重复使用的代码.除非我弄错了,所有这些代码确实定义NSApp为一个id世界.不幸的是没有帮助.
在我的搜索中,我设法找到了几个关于"全局常量"的引导,但是这样的事情:
extern NSString * const StringConstant;
Run Code Online (Sandbox Code Playgroud)
遗憾的是,它们仅限于编译时常量,并且无法映射到必要的类方法.
我希望能够推出自己NSApp风格的全局变量,这些变量映射到类方法[NSNotificationCenter defaultNotificationCenter].这可能吗?如果是这样,我应该怎么做呢?
我试图通过以下方式专门实现框架单例:
MySingletons.h
//...
extern id NSNotifCenter;
//...
Run Code Online (Sandbox Code Playgroud)
MySingletons.m
//...
+(void)initialize
{
NSNotifCenter = [NSNotificationCenter …Run Code Online (Sandbox Code Playgroud) 借助OS X 10.7上的Xcode 4,Lion,Apple引入了一种处理基于NIB的UI元素的空间关系的全新方式:自动布局.
在Auto Layouts的doc页面的顶部,Apple声明:
注意:自动布局仅适用于Mac OS X v10.7及更高版本.如果您在Mac OS X v10.6中运行Xcode 4,则无法使用自动布局.
乍一看,人们会认为Auto Layouts不会为Lion之前的系统编译或运行.但是,当我重新阅读通知和文档页面时,它开始看起来像预装Lion系统中的Xcode中不存在自动布局.
在基于Lion的计算机上编译后,自动布局是否可以在Lion之前的计算机上运行?我认为Apple可以通过将自动布局编译成类似弹簧/支柱的设置来实现这一目标.
constraints objective-c backwards-compatibility interface-builder
我目前正在开发一个Python脚本,它可以从MySQL数据库中提取一些数据.要访问此数据,我使用的是MySQLdb模块.
该模块遵循PEP 249(Python DB API)中规定的指导原则,涉及创建连接对象和后续游标对象,后者用于迭代信息.
目前,在我的项目中,每当我需要执行一个MySQL读/写块时,我都会创建一个连接对象,然后在我完成时关闭它.但是,我可以轻松地传递连接对象,以避免这些重复打开/关闭.
我的问题是:考虑到安全性,资源管理等,open; read/write; close; repeat for the next read/write;方法比方法更好open; read/write; pass connection on for the next read/write;吗?
编辑:更多背景.这个特定的Python脚本是多线程的.复杂的进程/线程环境是否会影响哪种方法更合适?
可能重复:
如何将Struct包装到NSObject中
可以将新的Clang Objective-C文字重定向到自定义类吗?
我有一个自定义结构:
typedef struct {
float f1;
float f2;
} MYCustomStruct;
Run Code Online (Sandbox Code Playgroud)
我需要添加到NSArray.我已经编写了一个类别来创建NSValues这些结构,然后我添加到其中NSArray,但是如果可能的话,我想进一步使用盒装表达式来简化它.我很想能够做到这一点:
@[@(instanceOfMYCustomStruct)];
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了以下错误:
非法类型'MYCustomStruct'用于盒装表达式
有没有办法使用带有自定义结构的盒装表达式?
我有一个简单的 Mac 应用程序,不打算用于任何类型的分发;只是个人使用。该应用程序是一个NSWindow包含MKMapView. 由于我没有 Mac 开发人员帐户,也不想要(请参阅“仅供个人使用”),因此我不会进行任何形式的代码签名或配置。
但是,在启动时,我得到一个空白地图和这个错误:
您的应用程序已尝试访问 Map Kit API。如果没有授权,您将无法访问此 API。您可能会从 Mac 开发人员计划获得一项权利,仅供您在 Mac App Store 应用程序中使用。有关 Apple Mac 开发人员计划的更多信息,请访问 developer.apple.com。
我真的需要购买 Mac 开发者帐户才能MKMapView在 OS X上使用吗?如果没有,我错过了什么?
我正在尝试map使用以下代码块通过对象进行迭代:
for(map<int, vector>::iterator table_iter = table.being(); table_iter != table.end(); table_iter++)
{
...
}
Run Code Online (Sandbox Code Playgroud)
而且我一直在收到错误告诉我:
从const_iterator转换为请求的非标量类型迭代器
而且我似乎无法确定为什么迭代器将会const与 - const或- 或如何处理它.
我正在尝试将方法添加到具有相同名称(但不同的参数集)的jQuery对象作为另一种方法.
到目前为止我得到了什么:
jQuery.fn.insertBefore = function(elem, duration)
{
this.css("display", "none");
this.insertBefore(elem);
this.toggle(duration);
}
Run Code Online (Sandbox Code Playgroud)
但是,此代码(特别是this.insertBefore(where);行)根据需要调用此函数,而不是jQueryinsertBefore()函数.为了将此函数添加到jQuery对象,并使其重载(不覆盖)现有函数,我需要做什么?
编辑:解决方案
(function ($)
{
var oldInsertBefore = $.fn.insertBefore;
jQuery.fn.insertBefore = function(elem, duration)
{
if (duration === undefined)
{
oldInsertBefore.call(this, elem);
return;
}
this.css("display", "none");
this.insertBefore(elem);
this.toggle(duration);
}
})(jQuery);
Run Code Online (Sandbox Code Playgroud) objective-c ×3
c++ ×2
iterator ×2
macros ×2
mapkit ×2
aws-lambda ×1
class-method ×1
cocoa ×1
const ×1
constraints ×1
generics ×1
geolocation ×1
ios ×1
javascript ×1
jquery ×1
map ×1
mkmapview ×1
mysql ×1
mysql-python ×1
netlify ×1
next.js ×1
overloading ×1
python ×1
reactjs ×1
stl ×1
struct ×1